@ -229,93 +229,93 @@ node.http.ServerResponse = function (connection, responses) {
/ * T h i s i s a w r a p p e r a r o u n d t h e L o w L e v e l S e r v e r i n t e r f a c e . I t p r o v i d e s
* connection handling , overflow checking , and some data buffering .
* /
node . http . Server = function ( RequestHandler , options ) {
if ( ! ( this instanceof node . http . Server ) )
throw Error ( "Constructor called as a function" ) ;
var server = this ;
function ConnectionHandler ( connection ) {
// An array of responses for each connection. In pipelined connections
// we need to keep track of the order they were sent.
var responses = [ ] ;
connection . onMessage = function ( ) {
var interrupted = false ;
// filled in ...
var req = { method : null // at onHeadersComplete
, uri : "" // at onURI
, httpVersion : null // at onHeadersComplete
, headers : [ ] // at onHeaderField, onHeaderValue
, onBody : null // by user
, onBodyComplete : null // by user
, interrupt : function ( ) { interrupted = true ; }
, setBodyEncoding : function ( enc ) {
connection . setEncoding ( enc ) ;
}
} ;
var res = new node . http . ServerResponse ( connection , responses ) ;
this . onURI = function ( data ) {
req . uri += data ;
return ! interrupted ;
} ;
var last_was_value = false ;
var headers = req . headers ;
this . onHeaderField = function ( data ) {
if ( headers . length > 0 && last_was_value == false )
headers [ headers . length - 1 ] [ 0 ] += data ;
else
headers . push ( [ data ] ) ;
last_was_value = false ;
return ! interrupted ;
} ;
this . onHeaderValue = function ( data ) {
var last_pair = headers [ headers . length - 1 ] ;
if ( last_pair . length == 1 )
last_pair [ 1 ] = data ;
else
last_pair [ 1 ] += data ;
last_was_value = true ;
return ! interrupted ;
} ;
this . onHeadersComplete = function ( ) {
req . httpVersion = this . httpVersion ;
req . method = this . method ;
// TODO parse the URI lazily?
req . uri = node . http . parseUri ( req . uri ) ;
res . should_keep_alive = this . should_keep_alive ;
RequestHandler . apply ( server , [ req , res ] ) ;
return ! interrupted ;
} ;
this . onBody = function ( chunk ) {
if ( req . onBody ) req . onBody ( chunk ) ;
return ! interrupted ;
} ;
this . onMessageComplete = function ( ) {
if ( req . onBodyComplete ) req . onBodyComplete ( ) ;
return ! interrupted ;
} ;
node . http . createServer = function ( requestHandler , options ) {
var server = new node . http . LowLevelServer ( ) ;
server . addListener ( "Connection" , node . http . connectionListener ) ;
//server.setOptions(options);
server . requestHandler = requestHandler ;
return server ;
} ;
node . http . connectionListener = function ( connection ) {
// An array of responses for each connection. In pipelined connections
// we need to keep track of the order they were sent.
var responses = [ ] ;
// is this really needed?
connection . addListener ( "EOF" , function ( ) {
if ( responses . length == 0 ) {
connection . close ( ) ;
} else {
responses [ responses . length - 1 ] . closeOnFinish = true ;
}
} ) ;
connection . onMessage = function ( ) {
var interrupted = false ;
// filled in ...
var req = { method : null // at onHeadersComplete
, uri : "" // at onURI
, httpVersion : null // at onHeadersComplete
, headers : [ ] // at onHeaderField, onHeaderValue
, onBody : null // by user
, onBodyComplete : null // by user
, interrupt : function ( ) { interrupted = true ; }
, setBodyEncoding : function ( enc ) {
connection . setEncoding ( enc ) ;
}
} ;
var res = new node . http . ServerResponse ( connection , responses ) ;
this . onURI = function ( data ) {
req . uri += data ;
return ! interrupted ;
} ;
// is this really needed?
connection . onEOF = function ( ) {
if ( responses . length == 0 ) {
connection . close ( ) ;
} else {
responses [ responses . length - 1 ] . closeOnFinish = true ;
}
var last_was_value = false ;
var headers = req . headers ;
this . onHeaderField = function ( data ) {
if ( headers . length > 0 && last_was_value == false )
headers [ headers . length - 1 ] [ 0 ] += data ;
else
headers . push ( [ data ] ) ;
last_was_value = false ;
return ! interrupted ;
} ;
}
this . __ proto__ = new node . http . LowLevelServer ( ConnectionHandler , options ) ;
this . onHeaderValue = function ( data ) {
var last_pair = headers [ headers . length - 1 ] ;
if ( last_pair . length == 1 )
last_pair [ 1 ] = data ;
else
last_pair [ 1 ] += data ;
last_was_value = true ;
return ! interrupted ;
} ;
this . onHeadersComplete = function ( ) {
req . httpVersion = this . httpVersion ;
req . method = this . method ;
// TODO parse the URI lazily?
req . uri = node . http . parseUri ( req . uri ) ;
res . should_keep_alive = this . should_keep_alive ;
connection . server . requestHandler . apply ( connection . server , [ req , res ] ) ;
return ! interrupted ;
} ;
this . onBody = function ( chunk ) {
if ( req . onBody ) req . onBody ( chunk ) ;
return ! interrupted ;
} ;
this . onMessageComplete = function ( ) {
if ( req . onBodyComplete ) req . onBodyComplete ( ) ;
return ! interrupted ;
} ;
} ;
} ;
node . http . Client = function ( port , host ) {