# Adding custom headers to the client

**URL:** https://discuss.elastic.co/t/adding-custom-headers-to-the-client/118077
**Category:** Kibana
**Created:** [February 1, 2018, 4:56pm UTC](https://discuss.elastic.co/t/adding-custom-headers-to-the-client/118077 "2018-02-01T16:56:21Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![robrotheram](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/robrotheram/32/27262_2.png) [@robrotheram](https://discuss.elastic.co/u/robrotheram)
#### Post date: [February 1, 2018, 4:56pm UTC](https://discuss.elastic.co/t/adding-custom-headers-to-the-client/118077/1 "2018-02-01T16:56:21Z")

</div>

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](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.

---

<div class="post-metadata">

### Author: ![jbudz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jbudz/32/45922_2.png) [@jbudz](https://discuss.elastic.co/u/jbudz)
#### Post date: [February 1, 2018, 5:41pm UTC](https://discuss.elastic.co/t/adding-custom-headers-to-the-client/118077/2 "2018-02-01T17:41:24Z")

</div>

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](https://github.com/elastic/kibana/blob/6.x/src/ui/public/chrome/directives/kbn_chrome.js) may be what you're looking for.

---

<div class="post-metadata">

### Author: ![robrotheram](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/robrotheram/32/27262_2.png) [@robrotheram](https://discuss.elastic.co/u/robrotheram)
#### Post date: [February 1, 2018, 5:57pm UTC](https://discuss.elastic.co/t/adding-custom-headers-to-the-client/118077/3 "2018-02-01T17:57:18Z")

</div>

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

---

<div class="post-metadata">

### Author: ![robrotheram](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/robrotheram/32/27262_2.png) [@robrotheram](https://discuss.elastic.co/u/robrotheram)
#### Post date: [February 2, 2018, 11:02am UTC](https://discuss.elastic.co/t/adding-custom-headers-to-the-client/118077/4 "2018-02-02T11:02:13Z")

</div>

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](https://stackoverflow.com/a/27372557)

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [March 2, 2018, 11:02am UTC](https://discuss.elastic.co/t/adding-custom-headers-to-the-client/118077/5 "2018-03-02T11:02:27Z")

</div>

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