1 var common = require('../common');
2 var assert = require('assert');
3 var http = require('http');
4 var url = require('url');
7 common.error(common.inspect(x));
10 var responses_sent = 0;
11 var responses_recvd = 0;
15 var server = http.Server(function(req, res) {
16 if (responses_sent == 0) {
17 assert.equal('GET', req.method);
18 assert.equal('/hello', url.parse(req.url).pathname);
20 console.dir(req.headers);
21 assert.equal(true, 'accept' in req.headers);
22 assert.equal('*/*', req.headers['accept']);
24 assert.equal(true, 'foo' in req.headers);
25 assert.equal('bar', req.headers['foo']);
28 if (responses_sent == 1) {
29 assert.equal('POST', req.method);
30 assert.equal('/world', url.parse(req.url).pathname);
34 req.on('end', function() {
35 res.writeHead(200, {'Content-Type': 'text/plain'});
36 res.write('The path was ' + url.parse(req.url).pathname);
42 //assert.equal('127.0.0.1', res.connection.remoteAddress);
44 server.listen(common.PORT);
46 server.on('listening', function() {
47 var agent = new http.Agent({ port: common.PORT, maxSockets: 1 });
51 headers: {'Accept': '*/*', 'Foo': 'bar'},
54 assert.equal(200, res.statusCode);
56 res.setEncoding('utf8');
57 res.on('data', function(chunk) { body0 += chunk; });
58 common.debug('Got /hello response');
61 setTimeout(function() {
62 var req = http.request({
68 assert.equal(200, res.statusCode);
70 res.setEncoding('utf8');
71 res.on('data', function(chunk) { body1 += chunk; });
72 common.debug('Got /world response');
78 process.on('exit', function() {
79 common.debug('responses_recvd: ' + responses_recvd);
80 assert.equal(2, responses_recvd);
82 common.debug('responses_sent: ' + responses_sent);
83 assert.equal(2, responses_sent);
85 assert.equal('The path was /hello', body0);
86 assert.equal('The path was /world', body1);