From: Ryan Dahl Date: Sat, 5 Dec 2009 07:37:46 +0000 (+0100) Subject: Bugfix: Don't use chunked encoding for 1.0 requests. X-Git-Tag: v0.1.21~8 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c5d82380f46ed0c992ff56a9e9ddfe6ab2540e62;p=platform%2Fupstream%2Fnodejs.git Bugfix: Don't use chunked encoding for 1.0 requests. http://groups.google.com/group/nodejs/browse_thread/thread/b2edb76691b1848c --- diff --git a/lib/http.js b/lib/http.js index 754b750..17846c1 100644 --- a/lib/http.js +++ b/lib/http.js @@ -312,11 +312,16 @@ OutgoingMessage.prototype.finish = function () { }; -function ServerResponse () { +function ServerResponse (req) { OutgoingMessage.call(this); this.should_keep_alive = true; this.use_chunked_encoding_by_default = true; + + if (req.httpVersionMajor < 1 || req.httpVersionMinor < 1) { + this.use_chunked_encoding_by_default = false; + this.should_keep_alive = false; + } } sys.inherits(ServerResponse, OutgoingMessage); exports.ServerResponse = ServerResponse; @@ -492,10 +497,10 @@ function connectionListener (connection) { createIncomingMessageStream(connection, function (incoming, should_keep_alive) { var req = incoming; - var res = new ServerResponse(connection); + var res = new ServerResponse(req); res.should_keep_alive = should_keep_alive; res.addListener("flush", function () { - if(flushMessageQueue(connection, responses)) { + if (flushMessageQueue(connection, responses)) { connection.close(); } }); diff --git a/test/mjsunit/test-http-1.0.js b/test/mjsunit/test-http-1.0.js new file mode 100644 index 0000000..ffc69e0 --- /dev/null +++ b/test/mjsunit/test-http-1.0.js @@ -0,0 +1,41 @@ +process.mixin(require("./common")); +tcp = require("tcp"); +http = require("http"); + +var port = 7333; + +var body = "hello world\n"; +var server_response = ""; +var client_got_eof = false; + +var server = http.createServer(function (req, res) { + res.sendHeader(200, {"Content-Type": "text/plain"}); + res.sendBody(body); + res.finish(); +}) +server.listen(port); + +var c = tcp.createConnection(port); + +c.setEncoding("utf8"); + +c.addListener("connect", function () { + c.send( "GET / HTTP/1.0\r\n\r\n" ); +}); + +c.addListener("receive", function (chunk) { + puts(chunk); + server_response += chunk; +}); + +c.addListener("eof", function () { + client_got_eof = true; + c.close(); + server.close(); +}); + +process.addListener("exit", function () { + var m = server_response.split("\r\n\r\n"); + assert.equal(m[1], body); + assert.equal(true, client_got_eof); +});