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');
|
|
|
|
const http = require('http');
|
2011-02-05 16:31:27 -08:00
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
const N = 1024;
|
2011-02-05 16:31:27 -08:00
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
const server = http.createServer(common.mustCall(function(req, res) {
|
2018-11-06 14:35:19 +00:00
|
|
|
assert.strictEqual(req.method, 'POST');
|
2017-01-08 13:19:00 +00:00
|
|
|
let bytesReceived = 0;
|
2016-07-15 15:43:24 -04:00
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
req.on('data', function(chunk) {
|
2013-06-12 23:51:17 +01:00
|
|
|
bytesReceived += chunk.length;
|
2011-02-05 16:31:27 -08:00
|
|
|
});
|
|
|
|
|
2016-07-15 15:43:24 -04:00
|
|
|
req.on('end', common.mustCall(function() {
|
|
|
|
assert.strictEqual(N, bytesReceived);
|
2011-02-05 16:31:27 -08:00
|
|
|
console.log('request complete from server');
|
2017-07-10 20:55:21 -04:00
|
|
|
res.writeHead(200, { 'Content-Type': 'text/plain' });
|
2011-02-05 16:31:27 -08:00
|
|
|
res.write('hello\n');
|
|
|
|
res.end();
|
2016-07-15 15:43:24 -04:00
|
|
|
}));
|
|
|
|
}));
|
2016-05-29 03:06:56 -04:00
|
|
|
server.listen(0);
|
2011-02-05 16:31:27 -08:00
|
|
|
|
2016-07-15 15:43:24 -04:00
|
|
|
server.on('listening', common.mustCall(function() {
|
2017-01-08 13:19:00 +00:00
|
|
|
const req = http.request({
|
2016-05-29 03:06:56 -04:00
|
|
|
port: this.address().port,
|
2011-08-14 15:02:14 +09:00
|
|
|
method: 'POST',
|
2011-10-04 18:08:18 -04:00
|
|
|
path: '/'
|
2016-07-15 15:43:24 -04:00
|
|
|
}, common.mustCall(function(res) {
|
2011-02-05 16:31:27 -08:00
|
|
|
res.setEncoding('utf8');
|
2011-10-15 01:08:36 +02:00
|
|
|
res.on('data', function(chunk) {
|
2011-02-05 16:31:27 -08:00
|
|
|
console.log(chunk);
|
|
|
|
});
|
2016-07-15 15:43:24 -04:00
|
|
|
res.on('end', common.mustCall(function() {
|
2011-02-05 16:31:27 -08:00
|
|
|
server.close();
|
2016-07-15 15:43:24 -04:00
|
|
|
}));
|
|
|
|
}));
|
2011-08-14 15:02:14 +09:00
|
|
|
|
2016-01-25 15:00:06 -08:00
|
|
|
req.write(Buffer.allocUnsafe(N));
|
2011-08-14 15:02:14 +09:00
|
|
|
req.end();
|
2016-07-15 15:43:24 -04:00
|
|
|
}));
|