Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/plugins/elasticsearch/lib/__tests__/call_with_request.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import expect from 'expect.js';
import { omit } from 'lodash';
import callWithRequest from '../call_with_request';

describe('call_with_request', () => {
Expand All @@ -13,16 +14,17 @@ describe('call_with_request', () => {
};
});

it ('passes through all headers', () => {
it ('passes through all headers except content-length', () => {
const mockRequest = {
headers: {
authorization: 'Basic QWxhZGRpbjpPcGVuU2VzYW1l',
'kbn-version': '4.6.0'
'kbn-version': '4.6.0',
'content-length': 44
}
};
return callWithRequest(mockClient)(mockRequest, 'search')
.then(() => {
expect(mockClient.params.headers).to.be(mockRequest.headers);
expect(mockClient.params.headers).to.eql(omit(mockRequest.headers, 'content-length'));
});
});
});
4 changes: 3 additions & 1 deletion src/plugins/elasticsearch/lib/call_with_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ const Boom = require('boom');
const getBasicAuthRealm = require('./get_basic_auth_realm');
const toPath = require('lodash/internal/toPath');

const PASSTHRU_HEADERS_BLACKLIST = [ 'content-length' ];

module.exports = (client) => {
return (req, endpoint, params = {}) => {
_.set(params, 'headers', req.headers);
_.set(params, 'headers', _.omit(req.headers, PASSTHRU_HEADERS_BLACKLIST));
const path = toPath(endpoint);
const api = _.get(client, path);
let apiContext = _.get(client, path.slice(0, -1));
Expand Down