2010-03-09 07:06:29 +08:00
|
|
|
require("../common");
|
2010-03-19 05:01:17 +08:00
|
|
|
net = require("net");
|
2010-03-20 10:22:04 +08:00
|
|
|
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-06-24 08:40:51 +08:00
|
|
|
console.log("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-04-09 01:44:22 +08:00
|
|
|
res.end();
|
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-03-19 05:01:17 +08:00
|
|
|
var c = net.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");
|
2010-04-09 01:44:22 +08:00
|
|
|
c.end();
|
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
|
|
|
});
|