class
ActionDispatch::Http::Headers
rails latest stable
- Superclass: ::Hash
Action Dispatch HTTP Headers
Provides access to the request’s HTTP headers from the environment.
env = { "CONTENT_TYPE" => "text/plain", "HTTP_USER_AGENT" => "curl/7.43.0" } headers = ActionDispatch::Http::Headers.from_hash(env) headers["Content-Type"] # => "text/plain" headers["User-Agent"] # => "curl/7.43.0"
Also note that when headers are mapped to CGI-like variables by the Rack server, both dashes and underscores are converted to underscores. This ambiguity cannot be resolved at this stage anymore. Both underscores and dashes have to be interpreted as if they were originally sent as dashes.
# GET / HTTP/1.1 # ... # User-Agent: curl/7.43.0 # X_Custom_Header: token headers["X_Custom_Header"] # => nil headers["X-Custom-Header"] # => "token"
Included modules
- Enumerable
Constants
CGI_VARIABLES = Set.new(%W[\nAUTH_TYPE\nCONTENT_LENGTH\nCONTENT_TYPE\nGATEWAY_INTERFACE\nHTTPS\nPATH_INFO\nPATH_TRANSLATED\nQUERY_STRING\nREMOTE_ADDR\nREMOTE_HOST\nREMOTE_IDENT\nREMOTE_USER\nREQUEST_METHOD\nSCRIPT_NAME\nSERVER_NAME\nSERVER_PORT\nSERVER_PROTOCOL\nSERVER_SOFTWARE\n]).freeze
DEFAULT = Object.new # :nodoc:
HTTP_HEADER = /\\A[A-Za-z0-9-]+\\z/
Files
- actionpack/lib/action_dispatch/http/headers.rb