Skip to content

Commit

Permalink
Merge pull request #7592 from ycombinator/call-with-request/passthru-…
Browse files Browse the repository at this point in the history
…all-headers

[4.x] Make callWithRequest pass through all headers
  • Loading branch information
ycombinator authored Jul 1, 2016
2 parents e369175 + 71fd41a commit 9f85332
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
28 changes: 28 additions & 0 deletions src/plugins/elasticsearch/lib/__tests__/call_with_request.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import expect from 'expect.js';
import callWithRequest from '../call_with_request';

describe('call_with_request', () => {
let mockClient;

beforeEach(() => {
mockClient = {
search(params) {
this.params = params;
return Promise.resolve(this);
}
};
});

it ('passes through all headers', () => {
const mockRequest = {
headers: {
authorization: 'Basic QWxhZGRpbjpPcGVuU2VzYW1l',
'kbn-version': '4.6.0'
}
};
return callWithRequest(mockClient)(mockRequest, 'search')
.then(() => {
expect(mockClient.params.headers).to.be(mockRequest.headers);
});
});
});
4 changes: 1 addition & 3 deletions src/plugins/elasticsearch/lib/call_with_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ const toPath = require('lodash/internal/toPath');

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

0 comments on commit 9f85332

Please sign in to comment.