Sebastialonso
Sebastialonso

Reputation: 1462

Custom headers in request not showing in Rails backend

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?

Upvotes: 6

Views: 2870

Answers (1)

usha
usha

Reputation: 29349

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

Upvotes: 16

Related Questions