nodejs/test/parallel/test-http-client-readable.js
Rich Trott 68ba9aa0fb test,lib,benchmark: match function names
In most cases, named functions match the variable or property to which
they are being assigned. That also seems to be the practice in a series
of PRs currently being evaluated that name currently-anonymous
functions.

This change applies that rule to instances in the code base that don't
comply with that practice.

This will be enforceable with a lint rule once we upgrade to ESLint
3.8.0.

PR-URL: https://github.com/nodejs/node/pull/9113
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
2016-10-19 22:20:27 -07:00

57 lines
1.1 KiB
JavaScript

'use strict';
const common = require('../common');
var assert = require('assert');
var http = require('http');
var util = require('util');
var Duplex = require('stream').Duplex;
function FakeAgent() {
http.Agent.call(this);
}
util.inherits(FakeAgent, http.Agent);
FakeAgent.prototype.createConnection = function createConnection() {
var s = new Duplex();
var once = false;
s._read = function _read() {
if (once)
return this.push(null);
once = true;
this.push('HTTP/1.1 200 Ok\r\nTransfer-Encoding: chunked\r\n\r\n');
this.push('b\r\nhello world\r\n');
this.readable = false;
this.push('0\r\n\r\n');
};
// Blackhole
s._write = function _write(data, enc, cb) {
cb();
};
s.destroy = s.destroySoon = function destroy() {
this.writable = false;
};
return s;
};
var received = '';
var req = http.request({
agent: new FakeAgent()
}, common.mustCall(function(res) {
res.on('data', function(chunk) {
received += chunk;
});
res.on('end', common.mustCall(function() {}));
}));
req.end();
process.on('exit', function() {
assert.equal(received, 'hello world');
});