2010-03-09 07:06:29 +08:00
|
|
|
require("../common");
|
2009-11-01 02:02:30 +08:00
|
|
|
tcp = require("tcp");
|
|
|
|
http = require("http");
|
2010-01-05 13:07:50 +08:00
|
|
|
url = require("url");
|
2009-09-04 23:35:38 +08:00
|
|
|
|
|
|
|
// Make sure no exceptions are thrown when receiving malformed HTTP
|
|
|
|
// requests.
|
|
|
|
|
|
|
|
nrequests_completed = 0;
|
2009-11-06 19:44:20 +08:00
|
|
|
nrequests_expected = 1;
|
2009-09-04 23:35:38 +08:00
|
|
|
|
2009-11-06 19:44:20 +08:00
|
|
|
var s = http.createServer(function (req, res) {
|
2010-01-05 13:07:50 +08:00
|
|
|
puts("req: " + JSON.stringify(url.parse(req.url)));
|
2009-09-04 23:35:38 +08:00
|
|
|
|
2010-02-26 04:54:48 +08:00
|
|
|
res.writeHead(200, {"Content-Type": "text/plain"});
|
2010-02-17 14:16:29 +08:00
|
|
|
res.write("Hello World");
|
2010-02-18 03:10:10 +08:00
|
|
|
res.close();
|
2009-09-04 23:35:38 +08:00
|
|
|
|
2009-11-06 19:44:20 +08:00
|
|
|
if (++nrequests_completed == nrequests_expected) s.close();
|
2009-09-04 23:35:38 +08:00
|
|
|
});
|
2010-02-27 04:06:32 +08:00
|
|
|
s.listen(PORT);
|
2009-09-04 23:35:38 +08:00
|
|
|
|
2010-02-27 04:06:32 +08:00
|
|
|
var c = tcp.createConnection(PORT);
|
2009-11-06 19:44:20 +08:00
|
|
|
c.addListener("connect", function () {
|
2010-02-17 05:15:30 +08:00
|
|
|
c.write("GET /hello?foo=%99bar HTTP/1.1\r\n\r\n");
|
2009-11-06 19:44:20 +08:00
|
|
|
c.close();
|
2009-09-04 23:35:38 +08:00
|
|
|
});
|
|
|
|
|
2009-11-06 19:44:20 +08:00
|
|
|
// TODO add more!
|
2009-09-04 23:35:38 +08:00
|
|
|
|
|
|
|
process.addListener("exit", function () {
|
2009-11-29 01:26:59 +08:00
|
|
|
assert.equal(nrequests_expected, nrequests_completed);
|
2009-09-04 23:35:38 +08:00
|
|
|
});
|