2010-02-25 07:36:17 +01:00
|
|
|
process.mixin(require("../common"));
|
2009-10-31 19:02:30 +01:00
|
|
|
http = require("http");
|
2009-07-31 18:34:27 +02:00
|
|
|
var PORT = 18032;
|
|
|
|
|
|
|
|
var sent_body = "";
|
|
|
|
var server_req_complete = false;
|
|
|
|
var client_res_complete = false;
|
|
|
|
|
2009-09-28 12:36:36 +02:00
|
|
|
var server = http.createServer(function(req, res) {
|
2009-11-28 18:26:59 +01:00
|
|
|
assert.equal("POST", req.method);
|
2009-07-31 18:34:27 +02:00
|
|
|
req.setBodyEncoding("utf8");
|
|
|
|
|
2010-02-17 07:16:29 +01:00
|
|
|
req.addListener('data', function (chunk) {
|
2009-07-31 18:34:27 +02:00
|
|
|
puts("server got: " + JSON.stringify(chunk));
|
|
|
|
sent_body += chunk;
|
|
|
|
});
|
|
|
|
|
2010-02-17 07:16:29 +01:00
|
|
|
req.addListener('end', function () {
|
2009-07-31 18:34:27 +02:00
|
|
|
server_req_complete = true;
|
|
|
|
puts("request complete from server");
|
2010-02-22 01:53:20 +01:00
|
|
|
res.writeHeader(200, {'Content-Type': 'text/plain'});
|
2010-02-17 07:16:29 +01:00
|
|
|
res.write('hello\n');
|
2010-02-17 20:10:10 +01:00
|
|
|
res.close();
|
2009-07-31 18:34:27 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
server.listen(PORT);
|
|
|
|
|
2009-09-28 12:36:36 +02:00
|
|
|
var client = http.createClient(PORT);
|
2009-12-02 23:25:56 +01:00
|
|
|
var req = client.request('POST', '/');
|
2009-08-26 18:22:00 +02:00
|
|
|
|
2010-02-17 07:16:29 +01:00
|
|
|
req.write('1\n');
|
|
|
|
req.write('2\n');
|
|
|
|
req.write('3\n');
|
2009-08-26 18:22:00 +02:00
|
|
|
|
|
|
|
puts("client finished sending request");
|
2010-02-17 20:10:10 +01:00
|
|
|
req.addListener('response', function(res) {
|
2009-08-26 18:22:00 +02:00
|
|
|
res.setBodyEncoding("utf8");
|
2010-02-17 07:16:29 +01:00
|
|
|
res.addListener('data', function(chunk) {
|
2009-08-26 18:22:00 +02:00
|
|
|
puts(chunk);
|
2009-07-31 18:34:27 +02:00
|
|
|
});
|
2010-02-17 07:16:29 +01:00
|
|
|
res.addListener('end', function() {
|
2009-08-26 18:22:00 +02:00
|
|
|
client_res_complete = true;
|
|
|
|
server.close();
|
|
|
|
});
|
|
|
|
});
|
2010-02-17 20:10:10 +01:00
|
|
|
req.close();
|
2009-07-31 18:34:27 +02:00
|
|
|
|
2009-08-26 18:51:04 +02:00
|
|
|
process.addListener("exit", function () {
|
2009-11-28 18:26:59 +01:00
|
|
|
assert.equal("1\n2\n3\n", sent_body);
|
|
|
|
assert.equal(true, server_req_complete);
|
|
|
|
assert.equal(true, client_res_complete);
|
2009-08-26 18:51:04 +02:00
|
|
|
});
|