Created
January 28, 2011 20:41
-
-
Save fallwith/800906 to your computer and use it in GitHub Desktop.
Rails controller code to dump raw HTTP headers from a request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
logger.warn "*** BEGIN RAW REQUEST HEADERS ***" | |
self.request.env.each do |header| | |
logger.warn "HEADER KEY: #{header[0]}" | |
logger.warn "HEADER VAL: #{header[1]}" | |
end | |
logger.warn "*** END RAW REQUEST HEADERS ***" |
@neilsy The HTTP_
prefix gets added for all request headers by rails / rack AFAIK, it does not come from the actual client request.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Log all request header keys (even if they don't start with "HTTP_", but no internal rails env stuff, in rails 5.1.4:
request.env.to_hash.select{ |key,val| ! key.starts_with?("rack") && ! key.starts_with?("action_")}
Integrating with a remote server with poorly documented auth, I needed to be able to see what the auth header was, and couldn't assume anything about the name. But I wanted to avoid logging anything about the internal state of the Rails instance to plain-text logs - in case there's anything secure in the rails env. This gets request headers (regardless of their naming convention) but no internal stuff, in rails 5.1.4.