Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var http = require('http');
  2. var url = require('url');
  3.  
  4.  
  5. function WSGI(_url) {
  6.     this.config = url.parse(_url);
  7.    
  8.     this._handleHTTP = function(env, callback) {
  9.         var site = http.createClient(this.config.port || 80, this.config.hostname);
  10.         var request = site.request('GET', this.config.pathname);
  11.         request.end();
  12.        
  13.         request.on('response', function(response) {
  14.             response.setEncoding('utf8');
  15.            
  16.             response.on('data', function(chunk) {
  17.                 callback(response, chunk);
  18.             });
  19.         });
  20.     }
  21.    
  22.     this.request = function(env, callback) {
  23.         switch(this.config.protocol) {
  24.             case 'http:':
  25.                 this._handleHTTP(env, callback);
  26.                 break;
  27.                
  28.             case 'file:':
  29.                 // NIY
  30.                 break;
  31.         }
  32.     }
  33. }
  34.  
  35.  
  36. exports.WSGI = WSGI;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement