# Unable to read headers from HTTP requests

**URL:** https://discuss.elastic.co/t/unable-to-read-headers-from-http-requests/53365
**Category:** Elasticsearch
**Tags:** elastic-stack-security
**Created:** [June 20, 2016, 7:50pm UTC](https://discuss.elastic.co/t/unable-to-read-headers-from-http-requests/53365 "2016-06-20T19:50:19Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![rmartin](https://avatars.discourse-cdn.com/v4/letter/r/7c8e57/32.png) [@rmartin](https://discuss.elastic.co/u/rmartin)
#### Post date: [June 20, 2016, 7:50pm UTC](https://discuss.elastic.co/t/unable-to-read-headers-from-http-requests/53365/1 "2016-06-20T19:50:20Z")

</div>

Hello,

I've come across a problem when writing a custom authentication Shield module in that headers do not seem to be accessible from the plugin. Here's what I've got:

In the CustomRealm itself, I've got a method like this:

public CustomAuthToken token(RestRequest request) {  
// my code here  
}

All that my code is doing at the moment is looking to see if a particular header is set in the request. Unfortunately, I can't see any headers in the request. I am definitely setting one (using Firefox Poster and curl as clients). When I print out the number of headers in the request, it is 0.

To try and solve the problem I've enabled the headers in the HTTP module (although this is for CORS rather than standard HTTP requests, but I wanted to rule it out).

The plugin is working fine and the method is being invoked when I send an HTTP request into Elastic, it is just that it claims to have no headers where there are some.

This is for ElasticSearch and Shield 2.3.

Many thanks,  
Russ.

---

<div class="post-metadata">

### Author: ![jaymode](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jaymode/32/50103_2.png) [@jaymode](https://discuss.elastic.co/u/jaymode)
#### Post date: [June 21, 2016, 5:40pm UTC](https://discuss.elastic.co/t/unable-to-read-headers-from-http-requests/53365/2 "2016-06-21T17:40:48Z")

</div>

In the constructor of your realms factory, can you try this:

```
@Inject
public CustomRealmFactory(ShieldSettingsFilter settingsFilter, RestController restController) {
    super(CustomRealm.TYPE, false);
    this.settingsFilter = settingsFilter;
    restController.registerRelevantHeaders("your header name");
}
```

---

<div class="post-metadata">

### Author: ![daveh](https://avatars.discourse-cdn.com/v4/letter/d/85e7bf/32.png) [@daveh](https://discuss.elastic.co/u/daveh)
#### Post date: [June 22, 2016, 4:03pm UTC](https://discuss.elastic.co/t/unable-to-read-headers-from-http-requests/53365/3 "2016-06-22T16:03:44Z")

</div>

Hello,

I have the exact same problem as rmartin. I have tried the possible fix suggested by jaymode but it unfortunately had no effect. I am wondering what my next step should be.

Dave

---

<div class="post-metadata">

### Author: ![jaymode](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jaymode/32/50103_2.png) [@jaymode](https://discuss.elastic.co/u/jaymode)
#### Post date: [June 22, 2016, 6:59pm UTC](https://discuss.elastic.co/t/unable-to-read-headers-from-http-requests/53365/4 "2016-06-22T18:59:20Z")

</div>

@daveh @russ are you both using the `RestRequest#header` method? There is a `getHeader` method but it will not contain the headers you are seeking (its confusing and will be changing in 5.0).

---

<div class="post-metadata">

### Author: ![rmartin](https://avatars.discourse-cdn.com/v4/letter/r/7c8e57/32.png) [@rmartin](https://discuss.elastic.co/u/rmartin)
#### Post date: [June 22, 2016, 7:29pm UTC](https://discuss.elastic.co/t/unable-to-read-headers-from-http-requests/53365/5 "2016-06-22T19:29:57Z")

</div>

Hi @jaymode,

Yep, that's the method I'm using. What is that method supposed to be for? Is there a way to get the headers from an HTTP request? If it's not possible, what would you recommend as an alternative? I could put the necessary info in as a parameter instead, perhaps?

Thanks,  
Russ.

---

<div class="post-metadata">

### Author: ![jaymode](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jaymode/32/50103_2.png) [@jaymode](https://discuss.elastic.co/u/jaymode)
#### Post date: [June 22, 2016, 7:48pm UTC](https://discuss.elastic.co/t/unable-to-read-headers-from-http-requests/53365/6 "2016-06-22T19:48:35Z")

</div>

The `RestRequest#header` method is how Shield gets the Authorization header. When you register your custom header, is it registered in the same case that you used it? In the example realm we do the following: [https://github.com/elastic/shield-custom-realm-example/blob/2.3/src/main/java/org/elasticsearch/example/realm/CustomRealm.java#L100-L109](https://github.com/elastic/shield-custom-realm-example/blob/2.3/src/main/java/org/elasticsearch/example/realm/CustomRealm.java#L100-L109)

How does that compare with your code?

---

<div class="post-metadata">

### Author: ![rmartin](https://avatars.discourse-cdn.com/v4/letter/r/7c8e57/32.png) [@rmartin](https://discuss.elastic.co/u/rmartin)
#### Post date: [June 23, 2016, 9:29pm UTC](https://discuss.elastic.co/t/unable-to-read-headers-from-http-requests/53365/7 "2016-06-23T21:29:55Z")

</div>

Yes, that was it. I picked the wrong headers method.

Thanks @jaymode

---

<div class="post-metadata">

### Author: ![daveh](https://avatars.discourse-cdn.com/v4/letter/d/85e7bf/32.png) [@daveh](https://discuss.elastic.co/u/daveh)
#### Post date: [June 29, 2016, 8:03pm UTC](https://discuss.elastic.co/t/unable-to-read-headers-from-http-requests/53365/8 "2016-06-29T20:03:52Z")

</div>

Sorted, thanks for the help

---

<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: [July 6, 2017, 1:43pm UTC](https://discuss.elastic.co/t/unable-to-read-headers-from-http-requests/53365/9 "2017-07-06T13:43:18Z")

</div>


