diff --git a/lib/response/generic.js b/lib/response/generic.js index b14672f4b..50da62890 100755 --- a/lib/response/generic.js +++ b/lib/response/generic.js @@ -105,7 +105,7 @@ internals.Generic.prototype._transmit = function (request, callback) { return send(); } - if (!self._headers['content-encoding']) { + if (!self._headers['Content-Encoding'] && !self._headers['content-encoding']) { var negotiator = new Negotiator(request.raw.req); var encoding = negotiator.preferredEncoding(['gzip', 'deflate', 'identity']); if (['gzip', 'deflate'].indexOf(encoding) !== -1) { diff --git a/lib/response/stream.js b/lib/response/stream.js index 2d087f098..6ec5b95c0 100755 --- a/lib/response/stream.js +++ b/lib/response/stream.js @@ -128,7 +128,7 @@ internals.Stream.prototype._transmit = function (request, callback) { var self = this; var encoder = null; - if (!this._headers['content-encoding']) { + if (!this._headers['Content-Encoding'] && !this._headers['content-encoding']) { var negotiator = new Negotiator(request.raw.req); var encoding = negotiator.preferredEncoding(['gzip', 'deflate', 'identity']); if (encoding === 'deflate' || encoding === 'gzip') { diff --git a/test/integration/gzip.js b/test/integration/gzip.js index 3858ac7c0..7ced8d371 100755 --- a/test/integration/gzip.js +++ b/test/integration/gzip.js @@ -40,6 +40,19 @@ describe('Payload', function () { server.route(postHandler); + var getHandler = { + method: 'GET', + path: '/', + config: { + handler: function (req) { + + req.reply('{"test":"true"}'); + } + } + }; + + server.route(getHandler); + before(function (done) { server.start(function () { @@ -121,7 +134,7 @@ describe('Payload', function () { }); }); - it('returns a gzip response when accept-encoding: gzip is requested', function (done) { + it('returns a gzip response on a post request when accept-encoding: gzip is requested', function (done) { var rawBody = '{"test":"true"}'; @@ -135,7 +148,21 @@ describe('Payload', function () { }); }); - it('returns a gzip response when accept-encoding: * is requested', function (done) { + it('returns a gzip response on a get request when accept-encoding: gzip is requested', function (done) { + + var rawBody = '{"test":"true"}'; + + Request.get({ url: uri, headers: { 'accept-encoding': 'gzip' } }, function (err, res, body) { + + Zlib.gzip(rawBody, function (err, zippedBody) { + + expect(body).to.equal(zippedBody.toString()); + done(); + }); + }); + }); + + it('returns a gzip response on a post request when accept-encoding: * is requested', function (done) { var rawBody = '{"test":"true"}'; @@ -149,7 +176,21 @@ describe('Payload', function () { }); }); - it('returns a deflate response when accept-encoding: deflate is requested', function (done) { + it('returns a gzip response on a get request when accept-encoding: * is requested', function (done) { + + var rawBody = '{"test":"true"}'; + + Request.get({ url: uri, headers: { 'accept-encoding': '*' } }, function (err, res, body) { + + Zlib.gzip(rawBody, function (err, zippedBody) { + + expect(body).to.equal(zippedBody.toString()); + done(); + }); + }); + }); + + it('returns a deflate response on a post request when accept-encoding: deflate is requested', function (done) { var rawBody = '{"test":"true"}'; @@ -163,7 +204,21 @@ describe('Payload', function () { }); }); - it('returns a gzip response when accept-encoding: gzip,q=1; deflate,q=.5 is requested', function (done) { + it('returns a deflate response on a get request when accept-encoding: deflate is requested', function (done) { + + var rawBody = '{"test":"true"}'; + + Request.get({ url: uri, headers: { 'accept-encoding': 'deflate' } }, function (err, res, body) { + + Zlib.deflate(rawBody, function (err, zippedBody) { + + expect(body).to.equal(zippedBody.toString()); + done(); + }); + }); + }); + + it('returns a gzip response on a post request when accept-encoding: gzip,q=1; deflate,q=.5 is requested', function (done) { var rawBody = '{"test":"true"}'; @@ -177,7 +232,21 @@ describe('Payload', function () { }); }); - it('returns a deflate response when accept-encoding: deflate,q=1; gzip,q=.5 is requested', function (done) { + it('returns a gzip response on a get request when accept-encoding: gzip,q=1; deflate,q=.5 is requested', function (done) { + + var rawBody = '{"test":"true"}'; + + Request.get({ url: uri, headers: { 'accept-encoding': 'gzip,q=1; deflate,q=.5' } }, function (err, res, body) { + + Zlib.gzip(rawBody, function (err, zippedBody) { + + expect(body).to.equal(zippedBody.toString()); + done(); + }); + }); + }); + + it('returns a deflate response on a post request when accept-encoding: deflate,q=1; gzip,q=.5 is requested', function (done) { var rawBody = '{"test":"true"}'; @@ -191,7 +260,21 @@ describe('Payload', function () { }); }); - it('returns a gzip response when accept-encoding: deflate, gzip is requested', function (done) { + it('returns a deflate response on a get request when accept-encoding: deflate,q=1; gzip,q=.5 is requested', function (done) { + + var rawBody = '{"test":"true"}'; + + Request.get({ url: uri, headers: { 'accept-encoding': 'deflate,q=1; gzip,q=.5' } }, function (err, res, body) { + + Zlib.deflate(rawBody, function (err, zippedBody) { + + expect(body).to.equal(zippedBody.toString()); + done(); + }); + }); + }); + + it('returns a gzip response on a post request when accept-encoding: deflate, gzip is requested', function (done) { var rawBody = '{"test":"true"}'; @@ -205,7 +288,21 @@ describe('Payload', function () { }); }); - it('returns an identity response when accept-encoding is missing', function (done) { + it('returns a gzip response on a get request when accept-encoding: deflate, gzip is requested', function (done) { + + var rawBody = '{"test":"true"}'; + + Request.get({ url: uri, headers: { 'accept-encoding': 'deflate, gzip' } }, function (err, res, body) { + + Zlib.gzip(rawBody, function (err, zippedBody) { + + expect(body).to.equal(zippedBody.toString()); + done(); + }); + }); + }); + + it('returns an identity response on a post request when accept-encoding is missing', function (done) { var rawBody = '{"test":"true"}'; @@ -215,4 +312,15 @@ describe('Payload', function () { done(); }); }); + + it('returns an identity response on a get request when accept-encoding is missing', function (done) { + + var rawBody = '{"test":"true"}'; + + Request.get({ url: uri, headers: {}}, function (err, res, body) { + + expect(body).to.equal(rawBody); + done(); + }); + }); }); \ No newline at end of file