diff --git a/lib/http.js b/lib/http.js index 754b750455..17846c1ca9 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 0000000000..ffc69e0808 --- /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); +});