@@ -230,7 +230,7 @@ exports.OutgoingMessage = OutgoingMessage;
230230OutgoingMessage . prototype . _send = function ( data , encoding ) {
231231 var length = this . output . length ;
232232
233- if ( length === 0 ) {
233+ if ( length === 0 || typeof data != 'string' ) {
234234 this . output . push ( data ) ;
235235 encoding = encoding || "ascii" ;
236236 this . outputEncodings . push ( encoding ) ;
@@ -242,11 +242,7 @@ OutgoingMessage.prototype._send = function (data, encoding) {
242242
243243 if ( ( lastEncoding === encoding ) ||
244244 ( ! encoding && data . constructor === lastData . constructor ) ) {
245- if ( lastData . constructor === String ) {
246- this . output [ length - 1 ] = lastData + data ;
247- } else {
248- this . output [ length - 1 ] = lastData . concat ( data ) ;
249- }
245+ this . output [ length - 1 ] = lastData + data ;
250246 return ;
251247 }
252248
@@ -332,7 +328,11 @@ OutgoingMessage.prototype.write = function (chunk, encoding) {
332328
333329 encoding = encoding || "ascii" ;
334330 if ( this . chunked_encoding ) {
335- this . _send ( process . _byteLength ( chunk , encoding ) . toString ( 16 ) ) ;
331+ if ( typeof chunk == 'string' ) {
332+ this . _send ( process . _byteLength ( chunk , encoding ) . toString ( 16 ) ) ;
333+ } else {
334+ this . _send ( chunk . length . toString ( 16 ) ) ;
335+ }
336336 this . _send ( CRLF ) ;
337337 this . _send ( chunk , encoding ) ;
338338 this . _send ( CRLF ) ;
@@ -531,21 +531,20 @@ function Client ( ) {
531531
532532 self . _reconnect = function ( ) {
533533 if ( self . readyState != "opening" ) {
534- // sys.debug("HTTP CLIENT: reconnecting readyState = " + self.readyState);
534+ sys . debug ( "HTTP CLIENT: reconnecting readyState = " + self . readyState ) ;
535535 self . connect ( self . port , self . host ) ;
536536 }
537537 } ;
538538
539539 self . _pushRequest = function ( req ) {
540540 req . addListener ( "flush" , function ( ) {
541- /*
542541 if ( self . readyState == "closed" ) {
543- // sys.debug("HTTP CLIENT request flush. reconnect. readyState = " + self.readyState);
542+ sys . debug ( "HTTP CLIENT request flush. reconnect. readyState = " + self . readyState ) ;
544543 self . _reconnect ( ) ;
545544 return ;
546545 }
547- */
548- // sys.debug("self flush readyState = " + self.readyState);
546+
547+ sys . debug ( "self flush readyState = " + self . readyState ) ;
549548 if ( req == currentRequest ) flushMessageQueue ( self , [ req ] ) ;
550549 } ) ;
551550 requests . push ( req ) ;
@@ -557,7 +556,8 @@ function Client ( ) {
557556
558557 self . addListener ( "connect" , function ( ) {
559558 parser . reinitialize ( 'response' ) ;
560- currentRequest = requests . shift ( ) ;
559+ sys . puts ( 'requests: ' + sys . inspect ( requests ) ) ;
560+ currentRequest = requests . shift ( )
561561 currentRequest . flush ( ) ;
562562 } ) ;
563563
@@ -575,7 +575,7 @@ function Client ( ) {
575575 return ;
576576 }
577577
578- // sys.debug("HTTP CLIENT onClose. readyState = " + self.readyState);
578+ sys . debug ( "HTTP CLIENT onClose. readyState = " + self . readyState ) ;
579579
580580 // If there are more requests to handle, reconnect.
581581 if ( requests . length > 0 ) {
@@ -602,7 +602,6 @@ exports.createClient = function (port, host) {
602602 var c = new Client ;
603603 c . port = port ;
604604 c . host = host ;
605- c . connect ( port , host ) ;
606605 return c ;
607606}
608607
0 commit comments