| 32 | }; |
| 33 | |
| 34 | function test(httpVersion, callback) { |
| 35 | const server = net.createServer(function(conn) { |
| 36 | const reply = `HTTP/${httpVersion} 200 OK\r\n\r\n${expected[httpVersion]}`; |
| 37 | |
| 38 | conn.end(reply); |
| 39 | }); |
| 40 | |
| 41 | server.listen(0, '127.0.0.1', common.mustCall(function() { |
| 42 | const options = { |
| 43 | host: '127.0.0.1', |
| 44 | port: this.address().port |
| 45 | }; |
| 46 | |
| 47 | const req = http.get(options, common.mustCall(function(res) { |
| 48 | let body = ''; |
| 49 | |
| 50 | res.on('data', function(data) { |
| 51 | body += data; |
| 52 | }); |
| 53 | |
| 54 | res.on('aborted', common.mustNotCall()); |
| 55 | res.on('end', common.mustCall(function() { |
| 56 | assert.strictEqual(body, expected[httpVersion]); |
| 57 | server.close(); |
| 58 | if (callback) process.nextTick(callback); |
| 59 | })); |
| 60 | })); |
| 61 | |
| 62 | req.on('error', function(err) { |
| 63 | throw err; |
| 64 | }); |
| 65 | })); |
| 66 | } |
| 67 | |
| 68 | test('0.9', function() { |
| 69 | test('1.0', function() { |