Rails provides a request.headers method that returns both all headers and a lot of extra non-header information… i would like to access only the request headers, how can I do so?
Regards
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You essentially have to isolate all environment entries which are prefixed with
HTTP_orCONTENT_, which correspond to your HTTP headers, e.g:Alternatively, you can be more restrictive and only look for specific HTTP headers in order to avoid accidentally picking up environment variables that may look like headers but are not actually valid such as
CONTENT_BLAorHTTP_DUMMY.Take a look at
actionpack/lib/action_controller/request.rbto see how they comb the environment to extract request headers.