Browse Source

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

http://groups.google.com/group/nodejs/browse_thread/thread/b2edb76691b1848c
v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
c5d82380f4
  1. 9
      lib/http.js
  2. 41
      test/mjsunit/test-http-1.0.js

9
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,7 +497,7 @@ 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)) {

41
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);
});
Loading…
Cancel
Save