|
|
@ -230,7 +230,7 @@ exports.OutgoingMessage = OutgoingMessage; |
|
|
|
OutgoingMessage.prototype._send = function (data, encoding) { |
|
|
|
var length = this.output.length; |
|
|
|
|
|
|
|
if (length === 0) { |
|
|
|
if (length === 0 || typeof data != 'string') { |
|
|
|
this.output.push(data); |
|
|
|
encoding = encoding || "ascii"; |
|
|
|
this.outputEncodings.push(encoding); |
|
|
@ -242,11 +242,7 @@ OutgoingMessage.prototype._send = function (data, encoding) { |
|
|
|
|
|
|
|
if ((lastEncoding === encoding) || |
|
|
|
(!encoding && data.constructor === lastData.constructor)) { |
|
|
|
if (lastData.constructor === String) { |
|
|
|
this.output[length-1] = lastData + data; |
|
|
|
} else { |
|
|
|
this.output[length-1] = lastData.concat(data); |
|
|
|
} |
|
|
|
this.output[length-1] = lastData + data; |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
@ -332,7 +328,11 @@ OutgoingMessage.prototype.write = function (chunk, encoding) { |
|
|
|
|
|
|
|
encoding = encoding || "ascii"; |
|
|
|
if (this.chunked_encoding) { |
|
|
|
this._send(process._byteLength(chunk, encoding).toString(16)); |
|
|
|
if (typeof chunk == 'string') { |
|
|
|
this._send(process._byteLength(chunk, encoding).toString(16)); |
|
|
|
} else { |
|
|
|
this._send(chunk.length.toString(16)); |
|
|
|
} |
|
|
|
this._send(CRLF); |
|
|
|
this._send(chunk, encoding); |
|
|
|
this._send(CRLF); |
|
|
@ -531,21 +531,20 @@ function Client ( ) { |
|
|
|
|
|
|
|
self._reconnect = function () { |
|
|
|
if (self.readyState != "opening") { |
|
|
|
//sys.debug("HTTP CLIENT: reconnecting readyState = " + self.readyState);
|
|
|
|
sys.debug("HTTP CLIENT: reconnecting readyState = " + self.readyState); |
|
|
|
self.connect(self.port, self.host); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
self._pushRequest = function (req) { |
|
|
|
req.addListener("flush", function () { |
|
|
|
/* |
|
|
|
if (self.readyState == "closed") { |
|
|
|
//sys.debug("HTTP CLIENT request flush. reconnect. readyState = " + self.readyState);
|
|
|
|
sys.debug("HTTP CLIENT request flush. reconnect. readyState = " + self.readyState); |
|
|
|
self._reconnect(); |
|
|
|
return; |
|
|
|
} |
|
|
|
*/ |
|
|
|
//sys.debug("self flush readyState = " + self.readyState);
|
|
|
|
|
|
|
|
sys.debug("self flush readyState = " + self.readyState); |
|
|
|
if (req == currentRequest) flushMessageQueue(self, [req]); |
|
|
|
}); |
|
|
|
requests.push(req); |
|
|
@ -557,7 +556,8 @@ function Client ( ) { |
|
|
|
|
|
|
|
self.addListener("connect", function () { |
|
|
|
parser.reinitialize('response'); |
|
|
|
currentRequest = requests.shift(); |
|
|
|
sys.puts('requests: ' + sys.inspect(requests)); |
|
|
|
currentRequest = requests.shift() |
|
|
|
currentRequest.flush(); |
|
|
|
}); |
|
|
|
|
|
|
@ -575,7 +575,7 @@ function Client ( ) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
//sys.debug("HTTP CLIENT onClose. readyState = " + self.readyState);
|
|
|
|
sys.debug("HTTP CLIENT onClose. readyState = " + self.readyState); |
|
|
|
|
|
|
|
// If there are more requests to handle, reconnect.
|
|
|
|
if (requests.length > 0) { |
|
|
@ -602,7 +602,6 @@ exports.createClient = function (port, host) { |
|
|
|
var c = new Client; |
|
|
|
c.port = port; |
|
|
|
c.host = host; |
|
|
|
c.connect(port, host); |
|
|
|
return c; |
|
|
|
} |
|
|
|
|
|
|
|