diff options
author | Mikeal Rogers <mikeal.rogers@gmail.com> | 2010-08-01 22:22:20 -0700 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2010-08-01 22:34:17 -0700 |
commit | 3214116be6bd088a02d0447f57b0ba15038adce0 (patch) | |
tree | a1c06459409a04254eaa0991a59673990e7ed6e3 /test/simple/test-http-keep-alive.js | |
parent | 71009ad3fe35af72af6694478405eaa3dc86ca35 (diff) | |
download | node-new-3214116be6bd088a02d0447f57b0ba15038adce0.tar.gz |
Implement keep-alive for http.Client
Send the 'Connection: keep-alive' header in your request to enable.
Diffstat (limited to 'test/simple/test-http-keep-alive.js')
-rw-r--r-- | test/simple/test-http-keep-alive.js | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/test/simple/test-http-keep-alive.js b/test/simple/test-http-keep-alive.js new file mode 100644 index 0000000000..edcb209597 --- /dev/null +++ b/test/simple/test-http-keep-alive.js @@ -0,0 +1,49 @@ +common = require("../common"); +assert = common.assert + +assert = require("assert"); +http = require("http"); +sys = require("sys"); + +body = "hello world\n"; +headers = {'connection':'keep-alive'} + +server = http.createServer(function (req, res) { + res.writeHead(200, {"Content-Length": body.length}); + res.write(body); + res.end(); +}); + +connectCount = 0; + +server.listen(common.PORT, function () { + var client = http.createClient(common.PORT); + + client.addListener("connect", function () { + common.error("CONNECTED") + connectCount++; + }) + + var request = client.request("GET", "/", headers); + request.end(); + request.addListener('response', function (response) { + common.error('response start'); + + + response.addListener("end", function () { + common.error('response end'); + var req = client.request("GET", "/", headers); + req.addListener('response', function (response) { + response.addListener("end", function () { + client.end(); + server.close(); + }) + }) + req.end(); + }); + }); +}); + +process.addListener('exit', function () { + assert.equal(1, connectCount); +}); |