From 6f7e165ce1b69ed712bd994a399209561e4d0943 Mon Sep 17 00:00:00 2001 From: Sascha Goebel Date: Fri, 6 Nov 2015 09:36:19 +0100 Subject: [PATCH 1/2] Always send Content-Length header. Fixes compatibility issues with elasticsearch behind nginx. See https://github.com/elastic/cookbook-elasticsearch/issues/38 or http://serverfault.com/questions/164220/is-there-a-way-to-avoid-nginx-411-content-length-required-errors --- src/lib/connectors/http.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib/connectors/http.js b/src/lib/connectors/http.js index fcaf91f3c..7d972a1cd 100644 --- a/src/lib/connectors/http.js +++ b/src/lib/connectors/http.js @@ -185,10 +185,11 @@ HttpConnector.prototype.request = function (params, cb) { request.setHeader('Content-Length', Buffer.byteLength(params.body, 'utf8')); request.end(params.body); } else { + request.setHeader('Content-Length', 0); request.end(); } return function () { request.abort(); }; -}; \ No newline at end of file +}; From 48667b2201220a3bb38dbcedae62df6b5f3e1bb4 Mon Sep 17 00:00:00 2001 From: Sascha Goebel Date: Mon, 30 Nov 2015 13:56:47 +0100 Subject: [PATCH 2/2] Mock setHeader to avoid multiple done() calls. --- test/mocks/request.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/mocks/request.js b/test/mocks/request.js index b2b2da7b8..01314c6e0 100644 --- a/test/mocks/request.js +++ b/test/mocks/request.js @@ -12,6 +12,7 @@ var http = require('http'); function MockRequest() { sinon.stub(this, 'end'); sinon.stub(this, 'write'); + sinon.stub(this, 'setHeader'); this.log = sinon.stub(this.log); } -util.inherits(MockRequest, http.ClientRequest); \ No newline at end of file +util.inherits(MockRequest, http.ClientRequest);