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) {
|
2017-01-08 15:36:25 +00:00
|
|
|
assert.strictEqual('POST', req.method);
|
2011-02-05 16:31:27 -08:00
|
|
|
|
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');
|
|
|
|
res.writeHead(200, {'Content-Type': 'text/plain'});
|
|
|
|
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
|
|
|
}));
|