diff --git a/package.json b/package.json index 855bb8b51..dde47b2e9 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "mocha": "^1.21.3", "mocha-lcov-reporter": "0.0.1", "moment": "~2.4.0", - "nock": "~0.28.1", + "nock": "~0.28.3", "open": "0.0.4", "optimist": "~0.6.0", "sinon": "~1.7.3", @@ -87,4 +87,4 @@ "engines": { "node": ">=0.8 <0.11" } -} \ No newline at end of file +} diff --git a/test/unit/specs/http_connector.js b/test/unit/specs/http_connector.js index 6e5a97f2e..def0b1569 100644 --- a/test/unit/specs/http_connector.js +++ b/test/unit/specs/http_connector.js @@ -356,7 +356,7 @@ describe('Http Connector', function () { }); }); - it('Can handle uncompress errors', function (done) { + it('Can handle decompression errors', function (done) { var server = nock('http://esjs.com:9200'); var con = new HttpConnection(new Host('http://esjs.com:9200')); var body = 'blah'; @@ -429,6 +429,38 @@ describe('Http Connector', function () { done(); }); }); + + it('does not set the Accept-Encoding header by default', function (done) { + var con = new HttpConnection(new Host()); + var respBody = 'i should not be encoded'; + var server = nock('http://localhost:9200') + .matchHeader('accept-encoding', undefined) + .get('/') + .once() + .reply(200, respBody); + + con.request({}, function (err, resp, status) { + expect(resp).to.be(respBody); + server.done(); + done(); + }); + }); + + it('sets the Accept-Encoding header when specified', function (done) { + var con = new HttpConnection(new Host({ suggestCompression: true })); + var respBody = 'i should be encoded'; + var server = nock('http://localhost:9200') + .matchHeader('accept-encoding', 'gzip,deflate') + .get('/') + .once() + .reply(200, respBody); + + con.request({}, function (err, resp, status) { + expect(resp).to.be(respBody); + server.done(); + done(); + }); + }); }); describe('Connection cleanup', function () {