2009-10-05 15:46:31 +02:00
|
|
|
node.mixin(require("common.js"));
|
2009-09-28 12:36:36 +02:00
|
|
|
http = require("/http.js");
|
2009-06-16 19:56:00 +02:00
|
|
|
PORT = 8888;
|
|
|
|
|
2009-06-18 14:50:10 +02:00
|
|
|
var body1_s = "1111111111111111";
|
|
|
|
var body2_s = "22222";
|
|
|
|
|
2009-09-28 12:36:36 +02:00
|
|
|
var server = http.createServer(function (req, res) {
|
2009-06-18 14:50:10 +02:00
|
|
|
var body = req.uri.path === "/1" ? body1_s : body2_s;
|
2009-08-23 12:20:25 +02:00
|
|
|
res.sendHeader(200, { "Content-Type": "text/plain"
|
|
|
|
, "Content-Length": body.length
|
|
|
|
});
|
2009-06-18 14:50:10 +02:00
|
|
|
res.sendBody(body);
|
2009-06-16 19:56:00 +02:00
|
|
|
res.finish();
|
2009-06-18 14:50:10 +02:00
|
|
|
});
|
2009-06-16 19:56:00 +02:00
|
|
|
server.listen(PORT);
|
|
|
|
|
2009-09-28 12:36:36 +02:00
|
|
|
var client = http.createClient(PORT);
|
2009-06-16 19:56:00 +02:00
|
|
|
|
|
|
|
var body1 = "";
|
|
|
|
var body2 = "";
|
|
|
|
|
2009-06-16 20:53:15 +02:00
|
|
|
client.get("/1").finish(function (res1) {
|
2009-06-16 19:56:00 +02:00
|
|
|
res1.setBodyEncoding("utf8");
|
|
|
|
|
2009-06-29 13:18:30 +02:00
|
|
|
res1.addListener("body", function (chunk) {
|
2009-06-27 20:40:43 +02:00
|
|
|
body1 += chunk;
|
|
|
|
});
|
2009-06-16 19:56:00 +02:00
|
|
|
|
2009-06-29 13:18:30 +02:00
|
|
|
res1.addListener("complete", function () {
|
2009-06-16 20:53:15 +02:00
|
|
|
client.get("/2").finish(function (res2) {
|
2009-06-16 19:56:00 +02:00
|
|
|
res2.setBodyEncoding("utf8");
|
2009-06-29 13:18:30 +02:00
|
|
|
res2.addListener("body", function (chunk) { body2 += chunk; });
|
|
|
|
res2.addListener("complete", function () { server.close(); });
|
2009-06-16 19:56:00 +02:00
|
|
|
});
|
2009-06-27 20:40:43 +02:00
|
|
|
});
|
2009-06-16 19:56:00 +02:00
|
|
|
});
|
|
|
|
|
2009-08-26 18:51:04 +02:00
|
|
|
process.addListener("exit", function () {
|
2009-06-18 14:50:10 +02:00
|
|
|
assertEquals(body1_s, body1);
|
|
|
|
assertEquals(body2_s, body2);
|
2009-08-26 18:51:04 +02:00
|
|
|
});
|