node/test/parallel/test-http-client-upload-buf.js
cjihrig ff1efa6087 test: use const for all require() calls
PR-URL: https://github.com/nodejs/node/pull/10550
Reviewed-By: Rich Trott <rtrott@gmail.com>
2017-01-02 18:28:18 -05:00

45 lines
1.0 KiB
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const http = require('http');
var N = 1024;
var server = http.createServer(common.mustCall(function(req, res) {
assert.equal('POST', req.method);
var bytesReceived = 0;
req.on('data', function(chunk) {
bytesReceived += chunk.length;
});
req.on('end', common.mustCall(function() {
assert.strictEqual(N, bytesReceived);
console.log('request complete from server');
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('hello\n');
res.end();
}));
}));
server.listen(0);
server.on('listening', common.mustCall(function() {
var req = http.request({
port: this.address().port,
method: 'POST',
path: '/'
}, common.mustCall(function(res) {
res.setEncoding('utf8');
res.on('data', function(chunk) {
console.log(chunk);
});
res.on('end', common.mustCall(function() {
server.close();
}));
}));
req.write(Buffer.allocUnsafe(N));
req.end();
}));