class ActionDispatch::Http::Headers

Experimental RBS support (using type sampling data from the type_fusion project).

# sig/action_dispatch/http/headers.rbs

class ActionDispatch::Http::Headers
  def []: (String key) -> nil
  def env_name: (String key) -> String
  def initialize: (ActionDispatch::Request request) -> void
end

headers # => “token”<br>headers # => nil
# X_Custom_Header: token
# User-Agent: curl/7.43.0
# …
# GET / HTTP/1.1
dashes have to be interpreted as if they were originally sent as dashes.
ambiguity cannot be resolved at this stage anymore. Both underscores and
server, both dashes and underscores are converted to underscores. This
Also note that when headers are mapped to CGI-like variables by the Rack<br><br>headers # => “curl/7.43.0”<br>headers # => “text/plain”
headers = ActionDispatch::Http::Headers.from_hash(env)
env = { “CONTENT_TYPE” => “text/plain”, “HTTP_USER_AGENT” => “curl/7.43.0” }
Provides access to the request’s HTTP headers from the environment.

def self.from_hash(hash)

def self.from_hash(hash)
  new ActionDispatch::Request.new hash
end

def [](key)

Experimental RBS support (using type sampling data from the type_fusion project).

def []: (String key) -> nil

This signature was generated using 1 sample from 1 application.

Returns the value for the given key mapped to @env.
def [](key)
  @req.get_header env_name(key)
end

def []=(key, value)

Sets the given value for the key mapped to @env.
def []=(key, value)
  @req.set_header env_name(key), value
end

def add(key, value)

Add a value to a multivalued header like +Vary+ or +Accept-Encoding+.
def add(key, value)
  @req.add_header env_name(key), value
end

def each(&block)

def each(&block)
  @req.each_header(&block)
end

def env; @req.env.dup; end

def env; @req.env.dup; end

def env_name(key)

Experimental RBS support (using type sampling data from the type_fusion project).

def env_name: (String key) -> String

This signature was generated using 4 samples from 1 application.

not contained within the headers hash.
Converts an HTTP header name to an environment variable name if it is
def env_name(key)
  key = key.to_s
  if HTTP_HEADER.match?(key)
    key = key.upcase
    key.tr!("-", "_")
    key.prepend("HTTP_") unless CGI_VARIABLES.include?(key)
  end
  key
end

def fetch(key, default = DEFAULT)

its result returned.
If the code block is provided, then it will be run and

raises a KeyError exception.
If the key is not found and an optional code block is not provided,

Returns the value for the given key mapped to @env.
def fetch(key, default = DEFAULT)
  @req.fetch_header(env_name(key)) do
    return default unless default == DEFAULT
    return yield if block_given?
    raise KeyError, key
  end
end

def initialize(request) # :nodoc:

Experimental RBS support (using type sampling data from the type_fusion project).

def initialize: (ActionDispatch::Request request) -> void

This signature was generated using 1 sample from 1 application.

:nodoc:
def initialize(request) # :nodoc:
  @req = request
end

def key?(key)

def key?(key)
  @req.has_header? env_name(key)
end

def merge(headers_or_env)

headers_or_env and the original instance.
Returns a new Http::Headers instance containing the contents of
def merge(headers_or_env)
  headers = @req.dup.headers
  headers.merge!(headers_or_env)
  headers
end

def merge!(headers_or_env)

headers_or_env.
entries; duplicate keys are overwritten with the values from
Adds the contents of headers_or_env to original instance
def merge!(headers_or_env)
  headers_or_env.each do |key, value|
    @req.set_header env_name(key), value
  end
end