-
-
Save fallwith/800906 to your computer and use it in GitHub Desktop.
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 ***" |
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.
@neilsy The HTTP_
prefix gets added for all request headers by rails / rack AFAIK, it does not come from the actual client request.
self.request.env.select {|k,v| k =~ /^HTTP_/}