2010-12-05 00:20:34 +01:00
|
|
|
var common = require('../common');
|
|
|
|
var assert = require('assert');
|
|
|
|
var net = require('net');
|
|
|
|
var http = require('http');
|
2010-12-05 23:33:52 +01:00
|
|
|
var url = require('url');
|
2009-09-04 17:35:38 +02:00
|
|
|
|
|
|
|
// Make sure no exceptions are thrown when receiving malformed HTTP
|
|
|
|
// requests.
|
|
|
|
|
2010-12-05 00:20:34 +01:00
|
|
|
var nrequests_completed = 0;
|
|
|
|
var nrequests_expected = 1;
|
2009-09-04 17:35:38 +02:00
|
|
|
|
2010-12-05 23:33:52 +01:00
|
|
|
var server = http.createServer(function(req, res) {
|
|
|
|
console.log('req: ' + JSON.stringify(url.parse(req.url)));
|
2009-09-04 17:35:38 +02:00
|
|
|
|
2010-12-05 23:33:52 +01:00
|
|
|
res.writeHead(200, {'Content-Type': 'text/plain'});
|
|
|
|
res.write('Hello World');
|
2010-04-08 19:44:22 +02:00
|
|
|
res.end();
|
2009-09-04 17:35:38 +02:00
|
|
|
|
2010-08-12 01:38:42 +02:00
|
|
|
if (++nrequests_completed == nrequests_expected) server.close();
|
2009-09-04 17:35:38 +02:00
|
|
|
});
|
2010-08-12 01:38:42 +02:00
|
|
|
server.listen(common.PORT);
|
2009-09-04 17:35:38 +02:00
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
server.on('listening', function() {
|
2010-08-12 01:38:42 +02:00
|
|
|
var c = net.createConnection(common.PORT);
|
2011-10-15 01:08:36 +02:00
|
|
|
c.on('connect', function() {
|
2010-12-05 23:33:52 +01:00
|
|
|
c.write('GET /hello?foo=%99bar HTTP/1.1\r\n\r\n');
|
2010-08-12 01:38:42 +02:00
|
|
|
c.end();
|
|
|
|
});
|
2009-09-04 17:35:38 +02:00
|
|
|
|
2010-08-12 01:38:42 +02:00
|
|
|
// TODO add more!
|
|
|
|
});
|
2009-09-04 17:35:38 +02:00
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
process.on('exit', function() {
|
2009-11-28 18:26:59 +01:00
|
|
|
assert.equal(nrequests_expected, nrequests_completed);
|
2009-09-04 17:35:38 +02:00
|
|
|
});
|