Permalink
Browse files

Don't encourage strange ideas about req race conditions

  • Loading branch information...
1 parent eda21cc commit cb79614f73bf4dbdadbb7290577e22094b8b502f @ry ry committed Jun 20, 2010
View
@@ -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)
@@ -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();
@@ -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);
@@ -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);
@@ -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');
@@ -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;
}
@@ -19,14 +19,14 @@ 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 () {
error('response end');
gotEnd = true;
});
});
- request.end();
});
process.addListener('exit', function () {
@@ -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 = "";
@@ -53,14 +53,14 @@ 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;
res.setBodyEncoding("utf8");
res.addListener('data', function (chunk) { body1 += chunk; });
debug("Got /world response");
});
- req.end();
}, 1);
process.addListener("exit", function () {

0 comments on commit cb79614

Please sign in to comment.