summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMikeal Rogers <mikeal.rogers@gmail.com>2010-08-01 22:22:20 -0700
committerRyan Dahl <ry@tinyclouds.org>2010-08-01 22:34:17 -0700
commit3214116be6bd088a02d0447f57b0ba15038adce0 (patch)
treea1c06459409a04254eaa0991a59673990e7ed6e3 /test
parent71009ad3fe35af72af6694478405eaa3dc86ca35 (diff)
downloadnode-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')
-rw-r--r--test/simple/test-http-keep-alive.js49
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);
+});