|
@ -372,7 +372,17 @@ OutgoingMessage.prototype.finish = function () { |
|
|
throw new Error("finish() has been renamed to close()."); |
|
|
throw new Error("finish() has been renamed to close()."); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
var closeWarning; |
|
|
|
|
|
|
|
|
OutgoingMessage.prototype.close = function (data, encoding) { |
|
|
OutgoingMessage.prototype.close = function (data, encoding) { |
|
|
|
|
|
if (!closeWarning) { |
|
|
|
|
|
closeWarning = "OutgoingMessage.prototype.close has been renamed to end()"; |
|
|
|
|
|
sys.error(closeWarning); |
|
|
|
|
|
} |
|
|
|
|
|
return this.end(data, encoding); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
OutgoingMessage.prototype.end = function (data, encoding) { |
|
|
if (data) this.write(data, encoding); |
|
|
if (data) this.write(data, encoding); |
|
|
if (this.chunkedEncoding) this._send("0\r\n\r\n"); // last chunk
|
|
|
if (this.chunkedEncoding) this._send("0\r\n\r\n"); // last chunk
|
|
|
this.finished = true; |
|
|
this.finished = true; |
|
@ -436,19 +446,34 @@ sys.inherits(ClientRequest, OutgoingMessage); |
|
|
exports.ClientRequest = ClientRequest; |
|
|
exports.ClientRequest = ClientRequest; |
|
|
|
|
|
|
|
|
ClientRequest.prototype.finish = function () { |
|
|
ClientRequest.prototype.finish = function () { |
|
|
throw new Error( "finish() has been renamed to close() and no longer takes " |
|
|
throw new Error( "finish() has been renamed to end() and no longer takes " |
|
|
+ "a response handler as an argument. Manually add a 'response' listener " |
|
|
+ "a response handler as an argument. Manually add a 'response' listener " |
|
|
+ "to the request object." |
|
|
+ "to the request object." |
|
|
); |
|
|
); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
var clientRequestCloseWarning; |
|
|
|
|
|
|
|
|
ClientRequest.prototype.close = function () { |
|
|
ClientRequest.prototype.close = function () { |
|
|
|
|
|
if (!clientRequestCloseWarning) { |
|
|
|
|
|
clientRequestCloseWarning = "Warning: ClientRequest.prototype.close has been renamed to end()"; |
|
|
|
|
|
sys.error(clientRequestCloseWarning); |
|
|
|
|
|
} |
|
|
|
|
|
if (arguments.length > 0) { |
|
|
|
|
|
throw new Error( "ClientRequest.prototype.end does not take any arguments. " |
|
|
|
|
|
+ "Add a response listener manually to the request object." |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
return this.end(); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
ClientRequest.prototype.end = function () { |
|
|
if (arguments.length > 0) { |
|
|
if (arguments.length > 0) { |
|
|
throw new Error( "ClientRequest.prototype.close does not take any arguments. " |
|
|
throw new Error( "ClientRequest.prototype.end does not take any arguments. " |
|
|
+ "Add a response listener manually to the request object." |
|
|
+ "Add a response listener manually to the request object." |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
OutgoingMessage.prototype.close.call(this); |
|
|
OutgoingMessage.prototype.end.call(this); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -509,7 +534,7 @@ function connectionListener (socket) { |
|
|
freeParser(parser); |
|
|
freeParser(parser); |
|
|
|
|
|
|
|
|
if (responses.length == 0) { |
|
|
if (responses.length == 0) { |
|
|
socket.close(); |
|
|
socket.end(); |
|
|
} else { |
|
|
} else { |
|
|
responses[responses.length-1].closeOnFinish = true; |
|
|
responses[responses.length-1].closeOnFinish = true; |
|
|
} |
|
|
} |
|
@ -525,7 +550,7 @@ function connectionListener (socket) { |
|
|
res.shouldKeepAlive = shouldKeepAlive; |
|
|
res.shouldKeepAlive = shouldKeepAlive; |
|
|
res.addListener('flush', function () { |
|
|
res.addListener('flush', function () { |
|
|
if (flushMessageQueue(socket, responses)) { |
|
|
if (flushMessageQueue(socket, responses)) { |
|
|
socket.close(); |
|
|
socket.end(); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
responses.push(res); |
|
|
responses.push(res); |
|
@ -582,7 +607,7 @@ function Client ( ) { |
|
|
parser.finish(); |
|
|
parser.finish(); |
|
|
|
|
|
|
|
|
debug("self got end closing. readyState = " + self.readyState); |
|
|
debug("self got end closing. readyState = " + self.readyState); |
|
|
self.close(); |
|
|
self.end(); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
self.addListener("close", function (e) { |
|
|
self.addListener("close", function (e) { |
|
@ -604,7 +629,7 @@ function Client ( ) { |
|
|
|
|
|
|
|
|
res.addListener('end', function ( ) { |
|
|
res.addListener('end', function ( ) { |
|
|
debug("request complete disconnecting. readyState = " + self.readyState); |
|
|
debug("request complete disconnecting. readyState = " + self.readyState); |
|
|
self.close(); |
|
|
self.end(); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
currentRequest.emit("response", res); |
|
|
currentRequest.emit("response", res); |
|
@ -697,7 +722,7 @@ exports.cat = function (url, encoding_, headers_) { |
|
|
req.addListener('response', function (res) { |
|
|
req.addListener('response', function (res) { |
|
|
if (res.statusCode < 200 || res.statusCode >= 300) { |
|
|
if (res.statusCode < 200 || res.statusCode >= 300) { |
|
|
if (callback) callback(res.statusCode); |
|
|
if (callback) callback(res.statusCode); |
|
|
client.close(); |
|
|
client.end(); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
res.setBodyEncoding(encoding); |
|
|
res.setBodyEncoding(encoding); |
|
@ -711,5 +736,5 @@ exports.cat = function (url, encoding_, headers_) { |
|
|
if (callback) callback(err); |
|
|
if (callback) callback(err); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
req.close(); |
|
|
req.end(); |
|
|
}; |
|
|
}; |
|
|