2010-07-15 20:47:25 +02:00
|
|
|
common = require("../common");
|
|
|
|
assert = common.assert
|
2010-03-18 22:01:17 +01:00
|
|
|
net = require("net");
|
2010-03-20 03:22:04 +01:00
|
|
|
http = require("http");
|
2009-12-23 21:48:14 +01:00
|
|
|
|
|
|
|
// wget sends an HTTP/1.0 request with Connection: Keep-Alive
|
|
|
|
//
|
2010-06-30 08:12:46 +02:00
|
|
|
// Sending back a chunked response to an HTTP/1.0 client would be wrong,
|
|
|
|
// so what has to happen in this case is that the connection is closed
|
|
|
|
// by the server after the entity body if the Content-Length was not
|
2009-12-23 21:48:14 +01:00
|
|
|
// sent.
|
|
|
|
//
|
2010-06-30 08:12:46 +02:00
|
|
|
// If the Content-Length was sent, we can probably safely honor the
|
|
|
|
// keep-alive request, even though HTTP 1.0 doesn't say that the
|
|
|
|
// connection can be kept open. Presumably any client sending this
|
|
|
|
// header knows that it is extending HTTP/1.0 and can handle the
|
|
|
|
// response. We don't test that here however, just that if the
|
|
|
|
// content-length is not provided, that the connection is in fact
|
2009-12-23 21:48:14 +01:00
|
|
|
// closed.
|
|
|
|
|
|
|
|
var server_response = "";
|
|
|
|
var client_got_eof = false;
|
|
|
|
var connection_was_closed = false;
|
|
|
|
|
|
|
|
var server = http.createServer(function (req, res) {
|
2010-02-25 21:54:48 +01:00
|
|
|
res.writeHead(200, {"Content-Type": "text/plain"});
|
2010-02-17 07:16:29 +01:00
|
|
|
res.write("hello ");
|
|
|
|
res.write("world\n");
|
2010-04-08 19:44:22 +02:00
|
|
|
res.end();
|
2009-12-23 21:48:14 +01:00
|
|
|
})
|
2010-07-15 20:47:25 +02:00
|
|
|
server.listen(common.PORT);
|
2009-12-23 21:48:14 +01:00
|
|
|
|
2010-07-15 20:47:25 +02:00
|
|
|
var c = net.createConnection(common.PORT);
|
2009-12-23 21:48:14 +01:00
|
|
|
|
|
|
|
c.setEncoding("utf8");
|
|
|
|
|
|
|
|
c.addListener("connect", function () {
|
2010-02-16 22:15:30 +01:00
|
|
|
c.write("GET / HTTP/1.0\r\n" +
|
2009-12-23 21:48:14 +01:00
|
|
|
"Connection: Keep-Alive\r\n\r\n");
|
|
|
|
});
|
|
|
|
|
2010-02-12 09:25:15 +01:00
|
|
|
c.addListener("data", function (chunk) {
|
2010-06-24 02:40:51 +02:00
|
|
|
console.log(chunk);
|
2009-12-23 21:48:14 +01:00
|
|
|
server_response += chunk;
|
|
|
|
});
|
|
|
|
|
2010-02-12 09:25:15 +01:00
|
|
|
c.addListener("end", function () {
|
2009-12-23 21:48:14 +01:00
|
|
|
client_got_eof = true;
|
2010-06-24 02:40:51 +02:00
|
|
|
console.log('got end');
|
2010-04-08 19:44:22 +02:00
|
|
|
c.end();
|
2009-12-23 21:48:14 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
c.addListener("close", function () {
|
|
|
|
connection_was_closed = true;
|
2010-06-24 02:40:51 +02:00
|
|
|
console.log('got close');
|
2009-12-23 21:48:14 +01:00
|
|
|
server.close();
|
|
|
|
});
|
|
|
|
|
|
|
|
process.addListener("exit", function () {
|
|
|
|
var m = server_response.split("\r\n\r\n");
|
|
|
|
assert.equal(m[1], "hello world\n");
|
|
|
|
assert.ok(client_got_eof);
|
|
|
|
assert.ok(connection_was_closed);
|
|
|
|
});
|