mirror of
https://github.com/nodejs/node.git
synced 2024-11-25 08:19:38 +01:00
3e1b1dd4a9
The copyright and license notice is already in the LICENSE file. There is no justifiable reason to also require that it be included in every file, since the individual files are not individually distributed except as part of the entire package.
60 lines
1.1 KiB
JavaScript
60 lines
1.1 KiB
JavaScript
var 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 ended = 0;
|
|
|
|
var req = http.request({
|
|
agent: new FakeAgent()
|
|
}, function(res) {
|
|
res.on('data', function(chunk) {
|
|
received += chunk;
|
|
});
|
|
|
|
res.on('end', function() {
|
|
ended++;
|
|
});
|
|
});
|
|
req.end();
|
|
|
|
process.on('exit', function() {
|
|
assert.equal(received, 'hello world');
|
|
assert.equal(ended, 1);
|
|
});
|