2010-07-16 02:47:25 +08:00
|
|
|
common = require("../common");
|
|
|
|
assert = common.assert
|
2010-03-19 05:01:17 +08:00
|
|
|
net = require("net");
|
2010-03-20 10:22:04 +08:00
|
|
|
http = require("http");
|
2009-12-05 15:37:46 +08:00
|
|
|
|
|
|
|
var body = "hello world\n";
|
|
|
|
var server_response = "";
|
|
|
|
var client_got_eof = false;
|
|
|
|
|
|
|
|
var server = http.createServer(function (req, res) {
|
2010-04-12 06:15:36 +08:00
|
|
|
assert.equal('1.0', req.httpVersion);
|
|
|
|
assert.equal(1, req.httpVersionMajor);
|
|
|
|
assert.equal(0, req.httpVersionMinor);
|
2010-02-26 04:54:48 +08:00
|
|
|
res.writeHead(200, {"Content-Type": "text/plain"});
|
2010-04-09 01:44:22 +08:00
|
|
|
res.end(body);
|
2009-12-05 15:37:46 +08:00
|
|
|
})
|
2010-07-16 02:47:25 +08:00
|
|
|
server.listen(common.PORT);
|
2009-12-05 15:37:46 +08:00
|
|
|
|
2010-08-12 07:38:42 +08:00
|
|
|
server.addListener("listening", function() {
|
|
|
|
var c = net.createConnection(common.PORT);
|
2009-12-05 15:37:46 +08:00
|
|
|
|
2010-08-12 07:38:42 +08:00
|
|
|
c.setEncoding("utf8");
|
2009-12-05 15:37:46 +08:00
|
|
|
|
2010-08-12 07:38:42 +08:00
|
|
|
c.addListener("connect", function () {
|
|
|
|
c.write( "GET / HTTP/1.0\r\n\r\n" );
|
|
|
|
});
|
2009-12-05 15:37:46 +08:00
|
|
|
|
2010-08-12 07:38:42 +08:00
|
|
|
c.addListener("data", function (chunk) {
|
|
|
|
console.log(chunk);
|
|
|
|
server_response += chunk;
|
|
|
|
});
|
2009-12-05 15:37:46 +08:00
|
|
|
|
2010-08-12 07:38:42 +08:00
|
|
|
c.addListener("end", function () {
|
|
|
|
client_got_eof = true;
|
|
|
|
c.end();
|
|
|
|
server.close();
|
|
|
|
});
|
2009-12-05 15:37:46 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
process.addListener("exit", function () {
|
|
|
|
var m = server_response.split("\r\n\r\n");
|
|
|
|
assert.equal(m[1], body);
|
|
|
|
assert.equal(true, client_got_eof);
|
|
|
|
});
|