Adding custom headers to the client

Hi there I am trying to do something that I except is kinda odd. I want to set a dynamic header that gets passed to our custom elasticsearch proxy that the user sets depending on certain criteria.

In Kibana 4 we had access to the $http object so I had something along the lines of if($rootScope.customHeader) { $http.headers = { 'custom': $rootScope.customHeader} }
sorry if my syntax is a bit off

How could one do that now in kibana 6?

I know the rest of the application bit works since I can use postman to test the kibana endpoint /elasticsearch/_msearch and set the headers and see it reach our proxy

I was looking at the courier in the call_clinet part
https://github.com/elastic/kibana/blob/6.0/src/ui/public/courier/fetch/call_client.js#L83 but could not see a obvious way of getting to the request headers.

Is this in the context of a separate plugin or a modification of core kibana? We're still using $http, https://github.com/elastic/kibana/blob/6.x/src/ui/public/chrome/directives/kbn_chrome.js may be what you're looking for.

In a perfect world it would be done by a plugin but since I need to add these custom headers to things like msearch it will probably need to add it to my kibana fork

Just to complete this thread with how I finally got dynamic http headers working. I used the $httpProvider.interceptors and pushed a factory that contains the rootscope from my plugin

this was the main inspriation I used to get it working https://stackoverflow.com/a/27372557

2 Likes

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.