diff --git a/doc/api.markdown b/doc/api.markdown index 952c40438d..9a4fd02bd5 100644 --- a/doc/api.markdown +++ b/doc/api.markdown @@ -1866,6 +1866,7 @@ Example of connecting to `google.com`: var google = http.createClient(80, 'www.google.com'); var request = google.request('GET', '/', {'host': 'www.google.com'}); + request.end(); request.addListener('response', function (response) { sys.puts('STATUS: ' + response.statusCode); sys.puts('HEADERS: ' + JSON.stringify(response.headers)); @@ -1874,7 +1875,6 @@ Example of connecting to `google.com`: sys.puts('BODY: ' + chunk); }); }); - request.end(); ### http.createClient(port, host, secure, credentials) diff --git a/test/pummel/test-http-client-reconnect-bug.js b/test/pummel/test-http-client-reconnect-bug.js index 2e963bb45a..a36a73fd79 100644 --- a/test/pummel/test-http-client-reconnect-bug.js +++ b/test/pummel/test-http-client-reconnect-bug.js @@ -25,10 +25,10 @@ client.addListener("end", function() { }); var request = client.request("GET", "/", {"host": "localhost"}); +request.end(); request.addListener('response', function(response) { sys.puts("STATUS: " + response.statusCode); }); -request.end(); setTimeout(function () { server.close(); diff --git a/test/simple/test-http-client-race-2.js b/test/simple/test-http-client-race-2.js index ba7a28bc1c..4f8604e4c8 100644 --- a/test/simple/test-http-client-race-2.js +++ b/test/simple/test-http-client-race-2.js @@ -38,6 +38,7 @@ var body3 = ""; // Client #1 is assigned Parser #1 // var req1 = client.request("/1") +req1.end(); req1.addListener('response', function (res1) { res1.setBodyEncoding("utf8"); @@ -63,6 +64,7 @@ req1.addListener('response', function (res1) { // internal state of the parser was no longer valid for use by Client #1. // var req2 = client.request("/2"); + req2.end(); req2.addListener('response', function (res2) { res2.setBodyEncoding("utf8"); res2.addListener('data', function (chunk) { body2 += chunk; }); @@ -73,19 +75,17 @@ req1.addListener('response', function (res1) { // request using client2. // var req3 = client2.request("/3"); + req3.end(); req3.addListener('response', function (res3) { res3.setBodyEncoding("utf8"); res3.addListener('data', function (chunk) { body3 += chunk }); res3.addListener('end', function() { server.close(); }); }); - req3.end(); }); }); - req2.end(); }, 500); }); }); -req1.end(); process.addListener("exit", function () { assert.equal(body1_s, body1); diff --git a/test/simple/test-http-client-race.js b/test/simple/test-http-client-race.js index e66964885c..016feae570 100644 --- a/test/simple/test-http-client-race.js +++ b/test/simple/test-http-client-race.js @@ -20,6 +20,7 @@ var body1 = ""; var body2 = ""; var req1 = client.request("/1") +req1.end(); req1.addListener('response', function (res1) { res1.setBodyEncoding("utf8"); @@ -29,15 +30,14 @@ req1.addListener('response', function (res1) { res1.addListener('end', function () { var req2 = client.request("/2"); + req2.end(); req2.addListener('response', function (res2) { res2.setBodyEncoding("utf8"); res2.addListener('data', function (chunk) { body2 += chunk; }); res2.addListener('end', function () { server.close(); }); }); - req2.end(); }); }); -req1.end(); process.addListener("exit", function () { assert.equal(body1_s, body1); diff --git a/test/simple/test-http-client-upload.js b/test/simple/test-http-client-upload.js index bdc1f2d674..82fd890739 100644 --- a/test/simple/test-http-client-upload.js +++ b/test/simple/test-http-client-upload.js @@ -26,7 +26,6 @@ server.listen(PORT); var client = http.createClient(PORT); var req = client.request('POST', '/'); - req.write('1\n'); req.write('2\n'); req.write('3\n'); diff --git a/test/simple/test-http-exceptions.js b/test/simple/test-http-exceptions.js index 042eedfbf3..b373f8fc9b 100644 --- a/test/simple/test-http-exceptions.js +++ b/test/simple/test-http-exceptions.js @@ -28,6 +28,7 @@ function check_reqs() { function add_client(num) { var req = http.createClient(PORT).request('GET', '/busy/' + num); + req.end(); req.addListener('response', function(res) { var response_body = ""; @@ -41,7 +42,6 @@ function add_client(num) { check_reqs(); }); }); - req.end(); return req; } diff --git a/test/simple/test-http-head-request.js b/test/simple/test-http-head-request.js index f1f92a92c7..befc8a2076 100644 --- a/test/simple/test-http-head-request.js +++ b/test/simple/test-http-head-request.js @@ -19,6 +19,7 @@ var gotEnd = false; server.listen(PORT, function () { var client = http.createClient(PORT); var request = client.request("HEAD", "/"); + request.end(); request.addListener('response', function (response) { error('response start'); response.addListener("end", function () { @@ -26,7 +27,6 @@ server.listen(PORT, function () { gotEnd = true; }); }); - request.end(); }); process.addListener('exit', function () { diff --git a/test/simple/test-http-proxy.js b/test/simple/test-http-proxy.js index 00ee3aff64..05f0c6050f 100644 --- a/test/simple/test-http-proxy.js +++ b/test/simple/test-http-proxy.js @@ -16,6 +16,7 @@ var proxy_client = http.createClient(BACKEND_PORT); var proxy = http.createServer(function (req, res) { debug("proxy req headers: " + JSON.stringify(req.headers)); var proxy_req = proxy_client.request(url.parse(req.url).pathname); + proxy_req.end(); proxy_req.addListener('response', function(proxy_res) { res.writeHead(proxy_res.statusCode, proxy_res.headers); proxy_res.addListener("data", function(chunk) { @@ -26,7 +27,6 @@ var proxy = http.createServer(function (req, res) { debug("proxy res"); }); }); - proxy_req.end(); }); var body = ""; diff --git a/test/simple/test-http.js b/test/simple/test-http.js index 8aab058f40..f424a2d112 100644 --- a/test/simple/test-http.js +++ b/test/simple/test-http.js @@ -53,6 +53,7 @@ req.addListener('response', function (res) { setTimeout(function () { req = client.request("POST", "/world"); + req.end(); req.addListener('response',function (res) { assert.equal(200, res.statusCode); responses_recvd += 1; @@ -60,7 +61,6 @@ setTimeout(function () { res.addListener('data', function (chunk) { body1 += chunk; }); debug("Got /world response"); }); - req.end(); }, 1); process.addListener("exit", function () {