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-12-01 14:12:17 -06:00
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
|
|
|
const http = require('http');
|
2011-04-25 16:04:07 -07:00
|
|
|
|
2016-12-01 14:12:17 -06:00
|
|
|
const server = http.createServer(function(req, res) {
|
2011-10-04 18:08:18 -04:00
|
|
|
res.writeHead(200, {
|
|
|
|
'Content-Type': 'text/plain',
|
|
|
|
'Connection': 'close'
|
|
|
|
});
|
2011-04-25 16:04:07 -07:00
|
|
|
res.write('hello ');
|
|
|
|
res.write('world\n');
|
|
|
|
res.end();
|
|
|
|
});
|
|
|
|
|
2015-10-06 21:12:45 -07:00
|
|
|
common.refreshTmpDir();
|
|
|
|
|
2016-07-15 15:43:24 -04:00
|
|
|
server.listen(common.PIPE, common.mustCall(function() {
|
2011-04-25 16:04:07 -07:00
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
const options = {
|
2011-07-21 21:25:46 +02:00
|
|
|
socketPath: common.PIPE,
|
2011-04-25 16:04:07 -07:00
|
|
|
path: '/'
|
|
|
|
};
|
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
const req = http.get(options, common.mustCall(function(res) {
|
2016-12-01 14:12:17 -06:00
|
|
|
assert.strictEqual(res.statusCode, 200);
|
|
|
|
assert.strictEqual(res.headers['content-type'], 'text/plain');
|
2011-07-21 00:36:54 +02:00
|
|
|
|
2011-04-25 16:04:07 -07:00
|
|
|
res.body = '';
|
|
|
|
res.setEncoding('utf8');
|
2011-07-21 00:36:54 +02:00
|
|
|
|
2011-10-04 18:08:18 -04:00
|
|
|
res.on('data', function(chunk) {
|
2011-04-25 16:04:07 -07:00
|
|
|
res.body += chunk;
|
|
|
|
});
|
2011-07-21 00:36:54 +02:00
|
|
|
|
2016-07-15 15:43:24 -04:00
|
|
|
res.on('end', common.mustCall(function() {
|
2016-12-01 14:12:17 -06:00
|
|
|
assert.strictEqual(res.body, 'hello world\n');
|
|
|
|
server.close(common.mustCall(function(error) {
|
|
|
|
assert.strictEqual(error, undefined);
|
|
|
|
server.close(common.mustCall(function(error) {
|
|
|
|
assert.strictEqual(error && error.message, 'Not running');
|
|
|
|
}));
|
|
|
|
}));
|
2016-07-15 15:43:24 -04:00
|
|
|
}));
|
|
|
|
}));
|
2011-04-25 16:04:07 -07:00
|
|
|
|
|
|
|
req.on('error', function(e) {
|
2017-04-09 10:53:30 -07:00
|
|
|
assert.fail(e.stack);
|
2011-04-25 16:04:07 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
req.end();
|
|
|
|
|
2016-07-15 15:43:24 -04:00
|
|
|
}));
|