Skip to content

Commit

Permalink
Fix for hapijs#2427
Browse files Browse the repository at this point in the history
  • Loading branch information
kanongil committed Feb 24, 2015
1 parent ce924d2 commit 07b7764
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/transmit.js
Expand Up @@ -312,7 +312,16 @@ internals.transmit = function (response, callback) {
var preview = (tap ? source.pipe(tap) : source);
var compressed = (compressor ? preview.pipe(compressor) : preview);
var ranged = (ranger ? compressed.pipe(ranger) : compressed);
ranged.pipe(request.raw.res);
ranged.pipe(request.raw.res, { end: false });

ranged.once('end', function () {

if (request.raw.req.complete === false) {
return; // Don't end requests that are still uploading
}

end();
});

// Injection

Expand Down
35 changes: 35 additions & 0 deletions test/payload.js
Expand Up @@ -8,6 +8,7 @@ var Code = require('code');
var Hapi = require('..');
var Hoek = require('hoek');
var Lab = require('lab');
var Wreck = require('wreck');


// Declare internals
Expand Down Expand Up @@ -153,6 +154,40 @@ describe('payload', function () {
});
});

it('returns 400 when payload is not consumed', function (done) {

var payload = new Buffer(10 * 1024 * 1024).toString();

var handler = function (request, reply) {

expect(request.payload.toString()).to.equal(payload);
return reply(request.payload);
};

var server = new Hapi.Server();
server.connection();
server.route({ method: 'POST', path: '/', config: { handler: handler, payload: { maxBytes: 10 } } });

server.start(function () {

var uri = 'http://localhost:' + server.info.port;

Wreck.post(uri, { payload: payload, agent: false }, function (err, res, body) {

expect(err).to.not.exist();
expect(res.statusCode).to.equal(400);
expect(body).to.exist();
Wreck.post(uri, { payload: payload, agent: false }, function (err, res, body) {

expect(err).to.not.exist();
expect(res.statusCode).to.equal(400);
expect(body).to.exist();
done();
});
});
});
});

it('peeks at unparsed data', function (done) {

var data = null;
Expand Down

0 comments on commit 07b7764

Please sign in to comment.