2017-01-03 13:16:48 -08:00
|
|
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the
|
|
|
|
// "Software"), to deal in the Software without restriction, including
|
|
|
|
// without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
|
|
// persons to whom the Software is furnished to do so, subject to the
|
|
|
|
// following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included
|
|
|
|
// in all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
|
|
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
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) {
|
2017-04-28 04:06:42 +03:00
|
|
|
console.log(`responding to ${request.url}`);
|
2010-04-28 19:25:43 -07:00
|
|
|
|
2017-07-10 20:55:21 -04:00
|
|
|
response.writeHead(200, { 'Content-Type': 'text/plain' });
|
2010-04-28 19:25:43 -07:00
|
|
|
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
|
|
|
|
2018-11-19 15:39:20 +05:30
|
|
|
server.listen(0, common.mustCall(() => {
|
|
|
|
http.get({ port: server.address().port }, common.mustCall((res) => {
|
2017-01-08 13:19:00 +00:00
|
|
|
let response = '';
|
2010-04-28 19:25:43 -07:00
|
|
|
|
2018-10-19 23:23:44 +02:00
|
|
|
assert.strictEqual(res.statusCode, 200);
|
2010-12-06 01:33:52 +03:00
|
|
|
res.setEncoding('ascii');
|
2018-11-19 15:39:20 +05:30
|
|
|
res.on('data', (chunk) => {
|
2010-04-28 19:25:43 -07:00
|
|
|
response += chunk;
|
|
|
|
});
|
2018-11-19 15:39:20 +05:30
|
|
|
res.on('end', common.mustCall(() => {
|
2018-10-19 23:23:44 +02:00
|
|
|
assert.strictEqual(response, '1\n2\n3\n');
|
2016-07-15 15:43:24 -04:00
|
|
|
}));
|
|
|
|
}));
|
|
|
|
}));
|