Permalink
Browse files

Bugfix: Don't use chunked encoding for 1.0 requests.

  • Loading branch information...
1 parent 7538e70 commit c5d82380f46ed0c992ff56a9e9ddfe6ab2540e62 @ry ry committed Dec 5, 2009
Showing with 49 additions and 3 deletions.
  1. +8 −3 lib/http.js
  2. +41 −0 test/mjsunit/test-http-1.0.js
View
@@ -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();
}
});
@@ -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);
+});

0 comments on commit c5d8238

Please sign in to comment.