node/test/simple/test-http-malformed-request.js

34 lines
772 B
JavaScript
Raw Normal View History

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