From 3fd13c6426b338196d138b0dc564020daed78bcd Mon Sep 17 00:00:00 2001 From: koichik Date: Tue, 31 Jan 2012 00:16:01 +0900 Subject: [PATCH] http: fix free http-parser too early when the status code is 100 (Continue). Fixes #2636. --- lib/http.js | 6 +++++- test/simple/test-http-expect-continue.js | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/http.js b/lib/http.js index a9aaac1c734..1d7eac32abf 100644 --- a/lib/http.js +++ b/lib/http.js @@ -1169,7 +1169,11 @@ ClientRequest.prototype.onSocket = function(socket) { socket.destroy(); } freeParser(); - } else if (parser.incoming && parser.incoming.complete) { + } else if (parser.incoming && parser.incoming.complete && + // When the status code is 100 (Continue), the server will + // send a final response after this client sends a request + // body. So, we must not free the parser. + parser.incoming.statusCode !== 100) { freeParser(); } }; diff --git a/test/simple/test-http-expect-continue.js b/test/simple/test-http-expect-continue.js index 3c3980a0ac9..54c04cce0ee 100644 --- a/test/simple/test-http-expect-continue.js +++ b/test/simple/test-http-expect-continue.js @@ -44,7 +44,9 @@ server.on('checkContinue', function(req, res) { common.debug('Server got Expect: 100-continue...'); res.writeContinue(); sent_continue = true; - handler(req, res); + setTimeout(function() { + handler(req, res); + }, 100); }); server.listen(common.PORT);