Any request sent to a Rails controller gets an HTTP_
prefixed to it, as that's appended by ActionDispatch::HTTP.Headers
. Is there a way to prevent that (without overriding ActionDispatch::HTTP
, so that I can use my custom headers, as is and use those as keys for headers.@env
?
Asked
Active
Viewed 2,209 times
4

absessive
- 1,121
- 5
- 14
- 36
1 Answers
4
No, it's not possible. That's how the ActionDispatch::Http::Headers
class is designed to normalize the headers.
private
def env_name(key)
key = key.to_s
if key =~ HTTP_HEADER
key = key.upcase.tr('-', '_')
key = "HTTP_" + key unless CGI_VARIABLES.include?(key)
end
key
end
You can still use your custom headers. You just need to reference them as HTTP_X_FOO
instead of x-foo
.

Simone Carletti
- 173,507
- 49
- 363
- 364
-
Yes, I've already seen how it does sets @env, which now needs the `HTTP_X_FOO` to get that header, and I'm forced to have to use those as keys while passing it as a hash. The intention was to avoid having to do that. – absessive Nov 14 '14 at 18:23
-
As I mentioned, it's not possible if you are using the Rails stack. – Simone Carletti Nov 14 '14 at 18:39