2009-09-21 00:19:33 +08:00
|
|
|
include("common.js");
|
2009-09-28 18:36:36 +08:00
|
|
|
http = require("/http.js");
|
2009-09-04 23:35:38 +08:00
|
|
|
|
|
|
|
// Make sure no exceptions are thrown when receiving malformed HTTP
|
|
|
|
// requests.
|
|
|
|
port = 9999;
|
|
|
|
|
|
|
|
nrequests_completed = 0;
|
|
|
|
nrequests_expected = 1;
|
|
|
|
|
2009-09-28 18:36:36 +08:00
|
|
|
var s = http.createServer(function (req, res) {
|
2009-09-04 23:35:38 +08:00
|
|
|
puts("req: " + JSON.stringify(req.uri));
|
|
|
|
|
|
|
|
res.sendHeader(200, {"Content-Type": "text/plain"});
|
|
|
|
res.sendBody("Hello World");
|
|
|
|
res.finish();
|
|
|
|
|
|
|
|
if (++nrequests_completed == nrequests_expected) s.close();
|
|
|
|
});
|
|
|
|
s.listen(port);
|
|
|
|
|
|
|
|
var c = node.tcp.createConnection(port);
|
|
|
|
c.addListener("connect", function () {
|
|
|
|
c.send("GET /hello?foo=%99bar HTTP/1.1\r\n\r\n");
|
|
|
|
c.close();
|
|
|
|
});
|
|
|
|
|
|
|
|
// TODO add more!
|
|
|
|
|
|
|
|
process.addListener("exit", function () {
|
|
|
|
assertEquals(nrequests_expected, nrequests_completed);
|
|
|
|
});
|