2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2016-07-15 15:43:24 -04:00
|
|
|
const common = require('../common');
|
2016-12-30 18:38:06 -05:00
|
|
|
const assert = require('assert');
|
2010-05-27 16:49:21 -07:00
|
|
|
|
2016-12-30 18:38:06 -05:00
|
|
|
const http = require('http');
|
2010-04-28 19:25:43 -07:00
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
const server = http.createServer(function(request, response) {
|
2010-06-23 17:40:51 -07:00
|
|
|
console.log('responding to ' + request.url);
|
2010-04-28 19:25:43 -07:00
|
|
|
|
|
|
|
response.writeHead(200, {'Content-Type': 'text/plain'});
|
|
|
|
response.write('1\n');
|
|
|
|
response.write('');
|
|
|
|
response.write('2\n');
|
|
|
|
response.write('');
|
|
|
|
response.end('3\n');
|
|
|
|
|
|
|
|
this.close();
|
2010-12-06 01:33:52 +03:00
|
|
|
});
|
2010-04-28 19:25:43 -07:00
|
|
|
|
2016-07-15 15:43:24 -04:00
|
|
|
server.listen(0, common.mustCall(function() {
|
|
|
|
http.get({ port: this.address().port }, common.mustCall(function(res) {
|
2017-01-08 13:19:00 +00:00
|
|
|
let response = '';
|
2010-04-28 19:25:43 -07:00
|
|
|
|
2017-01-08 15:36:25 +00:00
|
|
|
assert.strictEqual(200, res.statusCode);
|
2010-12-06 01:33:52 +03:00
|
|
|
res.setEncoding('ascii');
|
2011-10-15 01:08:36 +02:00
|
|
|
res.on('data', function(chunk) {
|
2010-04-28 19:25:43 -07:00
|
|
|
response += chunk;
|
|
|
|
});
|
2016-07-15 15:43:24 -04:00
|
|
|
res.on('end', common.mustCall(function() {
|
|
|
|
assert.strictEqual('1\n2\n3\n', response);
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
}));
|