Browse Source

Don't encourage strange ideas about req race conditions

v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
cb79614f73
  1. 2
      doc/api.markdown
  2. 2
      test/pummel/test-http-client-reconnect-bug.js
  3. 6
      test/simple/test-http-client-race-2.js
  4. 4
      test/simple/test-http-client-race.js
  5. 1
      test/simple/test-http-client-upload.js
  6. 2
      test/simple/test-http-exceptions.js
  7. 2
      test/simple/test-http-head-request.js
  8. 2
      test/simple/test-http-proxy.js
  9. 2
      test/simple/test-http.js

2
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)

2
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();

6
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);

4
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);

1
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');

2
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;
}

2
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 () {

2
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 = "";

2
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 () {

Loading…
Cancel
Save