5

I'm working with a Rails 4 API backend and a mobile app in both Android in iOS. Using Nginx and Unicorn.

To obtain certain data, the cliens must send me (among other things) a user id in the request's headers. We're using a custom header, for example WWW_CUSTOM_NAME, explained here. I'm aware that in Rails 4, I can capture the value in these custom headers by doing something like

request.headers["HTTP_WWW_CUSTOM_NAME"]

Indeed, this worked every single time my team and I worked in development. But when we pushed the code to the production server, the approach didn't work.

It's almost like the custom header is gone in production. I tried the same thing without the extra "HTTP_", removing capitals letter, and nothing worked. But in development works okay.

Any idea why this must be?

Community
  • 1
  • 1
Sebastialonso
  • 1,437
  • 18
  • 34

1 Answers1

16

If you are using nginx, this could be your problem

You have two options

  1. Change your custom header to use X-WWW-CUSTOM-NAME
  2. Turn on underscores_in_headers

First option would be better I think

usha
  • 28,973
  • 5
  • 72
  • 93
  • I am using Nginx, forgot to mention that. Just to clarify, the client should sent something like `X-WWW-CUSTOM-NAME`? If so, should I then pick it up like `HTTP-X-WWW-CUSTOM-NAME`? – Sebastialonso Aug 28 '14 at 21:42
  • 1
    You can access it like `request.headers["X-WWW-CUSTOM-NAME"]` – usha Aug 28 '14 at 21:47
  • Yes, I can. I tried it 5 minutes ago, and it worked. Thank you very much. Accepted answer. – Sebastialonso Aug 28 '14 at 21:49