|
@ -3,7 +3,10 @@ PORT = 8888; |
|
|
|
|
|
|
|
|
var server = new node.http.Server(function (req, res) { |
|
|
var server = new node.http.Server(function (req, res) { |
|
|
res.sendHeader(200, [["content-type", "text/plain"]]); |
|
|
res.sendHeader(200, [["content-type", "text/plain"]]); |
|
|
res.sendBody("hello world\n"); |
|
|
if (req.uri.path == "/1") |
|
|
|
|
|
res.sendBody("hello world 1\n"); |
|
|
|
|
|
else |
|
|
|
|
|
res.sendBody("hello world 2\n"); |
|
|
res.finish(); |
|
|
res.finish(); |
|
|
}) |
|
|
}) |
|
|
server.listen(PORT); |
|
|
server.listen(PORT); |
|
@ -13,13 +16,13 @@ var client = new node.http.Client(PORT); |
|
|
var body1 = ""; |
|
|
var body1 = ""; |
|
|
var body2 = ""; |
|
|
var body2 = ""; |
|
|
|
|
|
|
|
|
client.get("/").finish(function (res1) { |
|
|
client.get("/1").finish(function (res1) { |
|
|
res1.setBodyEncoding("utf8"); |
|
|
res1.setBodyEncoding("utf8"); |
|
|
|
|
|
|
|
|
res1.onBody = function (chunk) { body1 += chunk; }; |
|
|
res1.onBody = function (chunk) { body1 += chunk; }; |
|
|
|
|
|
|
|
|
res1.onBodyComplete = function () { |
|
|
res1.onBodyComplete = function () { |
|
|
client.get("/").finish(function (res2) { |
|
|
client.get("/2").finish(function (res2) { |
|
|
res2.setBodyEncoding("utf8"); |
|
|
res2.setBodyEncoding("utf8"); |
|
|
res2.onBody = function (chunk) { body2 += chunk; }; |
|
|
res2.onBody = function (chunk) { body2 += chunk; }; |
|
|
res2.onBodyComplete = function () { |
|
|
res2.onBodyComplete = function () { |
|
@ -30,6 +33,6 @@ client.get("/").finish(function (res1) { |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
function onExit () { |
|
|
function onExit () { |
|
|
assertEqual("hello world\n", body1); |
|
|
assertEquals("hello world 1\n", body1); |
|
|
assertEqual("hello world\n", body2); |
|
|
assertEquals("hello world 2\n", body2); |
|
|
} |
|
|
} |
|
|