Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
plugins.buffer: do not ignore buffer:false on request level
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Blasnik committed Jul 28, 2015
1 parent c5bbe7f commit ff19bab
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/plugins/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ BufferPlugin.prototype._setup = function() {

this._rail.on('plugin-response', function(call, options, response) {
// HEAD responses are buffered too, acting as stream terminator
if (self.default || options.buffer && options.buffer !== false) {
if (self.default && options.buffer !== false ||
!self.default && options.buffer === true) {
self.intercept(call);
}
});
Expand Down
31 changes: 31 additions & 0 deletions test/test-http-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,37 @@ suite('http:buffer', function() {
});


test('call w/ buffer=false (request)', function(done) {
onrequest = function(request, response) {
response.end('pong');
};

rail.call({
proto: 'http',
port: common.port,
buffer: false
}, function(response) {
assert.strictEqual(response.statusCode, 200);

assert(!response.buffer);
assert(response instanceof http.IncomingMessage);

var data = [];
response.on('readable', function() {
data.push(new Buffer(response.read()));
});

response.on('end', function() {
var data_ = Buffer.concat(data);
assert.strictEqual(data_.length, 4);
assert.strictEqual(data_.toString(), 'pong');
done();
});

}).end();
});


suiteTeardown(function(done) {
server.close(done);
});
Expand Down

0 comments on commit ff19bab

Please sign in to comment.