# Request headers name normalization

**URL:** <https://discuss.rubyonrails.org/t/request-headers-name-normalization/69746>\
**Category:** rubyonrails-talk\
**Created:** [October 18, 2014, 8:49pm UTC](https://discuss.rubyonrails.org/t/request-headers-name-normalization/69746 "2014-10-18T20:49:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roman](https://avatars.discourse-cdn.com/v4/letter/r/ed8c4c/32.png) [@Roman](https://discuss.rubyonrails.org/u/Roman)\
**Post date:** [October 18, 2014, 8:49pm UTC](https://discuss.rubyonrails.org/t/request-headers-name-normalization/69746/1 "2014-10-18T20:49:04Z")

</div>

I believe, there’s inconsistency between how Rails and curl normalize header names.

If I do a `curl -H "some_header: value"` it will send the header as `HTTP_SOME_HEADER`. Then in Rails controller I would expect that header to be accessible as `request.headers[:some_header]`, but it’s not. The culprit is in the `[ActionDispatch::Http::Headers#env_name](https://github.com/rails/rails/blob/e994fa11cfdb3fc6d96068dbb40c309783563b04/actionpack/lib/action_dispatch/http/headers.rb#L89-L96)`, which doesn’t adjust the header name if it contains an underscore.

Which of the two is correct? Do you think the issue could addressed in Rails?

---

<div class="post-metadata">

**Author:** ![Andre\_Orvalho1](https://avatars.discourse-cdn.com/v4/letter/a/b4bc9f/32.png) [@Andre\_Orvalho1](https://discuss.rubyonrails.org/u/Andre_Orvalho1)\
**Post date:** [October 23, 2014, 7:59am UTC](https://discuss.rubyonrails.org/t/request-headers-name-normalization/69746/2 "2014-10-23T07:59:23Z")

</div>

I am not sure I understand your question, but how does the headers hash look like? maybe if you show me the result will be easier to understand the mistake!

Also gives a concrete example of which headers you trying to set.

I have always done curl requests like this:

curl -i --header “Accept: application/json” --header “Content-Type: application/json”

the -i option from the manual:

-i, --include

(HTTP) Include the HTTP-header in the output. The HTTP-header includes things like server-

name, date of the document, HTTP-version and more…

so you can see the answer to your curl call.

---

<div class="post-metadata">

**Author:** ![Roman](https://avatars.discourse-cdn.com/v4/letter/r/ed8c4c/32.png) [@Roman](https://discuss.rubyonrails.org/u/Roman)\
**Post date:** [October 23, 2014, 8:39am UTC](https://discuss.rubyonrails.org/t/request-headers-name-normalization/69746/3 "2014-10-23T08:39:40Z")

</div>

I figured, it’s not related to curl but to Rails and Rack only. Here’s what I do:

curl -v -H “hello\_world: true” localhost:3000/empty

Now in the controller I dump the request headers and see “HTTP\_HELLO\_WORLD”=\>“true”. Rack converted “hello\_world” to “HTTP\_HELLO\_WORLD”. But if I try to access the header like `request.headers[:hello_world]` or `request.headers["hello_world"]`, it will return nil.

If I used ‘hello-world’ instead of ‘hello\_world’ (underscore instead of dash), everything would have worked as expected.

---

<div class="post-metadata">

**Author:** ![Anuj\_Dutta](https://avatars.discourse-cdn.com/v4/letter/a/db5fbb/32.png) [@Anuj\_Dutta](https://discuss.rubyonrails.org/u/Anuj_Dutta)\
**Post date:** [October 23, 2014, 8:55am UTC](https://discuss.rubyonrails.org/t/request-headers-name-normalization/69746/4 "2014-10-23T08:55:57Z")

</div>

Hello Roman,

I wrote a blog post about it a while ago:

[http://www.andhapp.com/blog/2013/03/03/rack-nginx-custom-http-header-http\_-and-\_/](http://www.andhapp.com/blog/2013/03/03/rack-nginx-custom-http-header-http_-and-_/)

I hope it helps.

Anuj

---

<div class="post-metadata">

**Author:** ![Roman](https://avatars.discourse-cdn.com/v4/letter/r/ed8c4c/32.png) [@Roman](https://discuss.rubyonrails.org/u/Roman)\
**Post date:** [October 23, 2014, 9:13am UTC](https://discuss.rubyonrails.org/t/request-headers-name-normalization/69746/5 "2014-10-23T09:13:14Z")

</div>

Thanks, Anuj. I didn’t know that nginx also makes its contribution to confusion with headers.
