123456789_123456789_123456789_123456789_123456789_

Module: Rack::Request::Env

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Included In:
Defined in: lib/rack/request.rb

Instance Attribute Summary

  • #env readonly

    The environment of the request.

Instance Method Summary

Instance Attribute Details

#env (readonly)

The environment of the request.

[ GitHub ]

  
# File 'lib/rack/request.rb', line 84

attr_reader :env

Instance Method Details

#add_header(key, v)

Add a header that may have multiple values.

Example:

request.add_header 'Accept', 'image/png'
request.add_header 'Accept', '*/*'

assert_equal 'image/png,*/*', request.get_header('Accept')

www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2

[ GitHub ]

  
# File 'lib/rack/request.rb', line 129

def add_header(key, v)
  if v.nil?
    get_header key
  elsif has_header? key
    set_header key, "#{get_header key},#{v}"
  else
    set_header key, v
  end
end

#delete_header(name)

Delete a request specific value for name.

[ GitHub ]

  
# File 'lib/rack/request.rb', line 140

def delete_header(name)
  @env.delete name
end

#each_header(&block)

Loops through each key / value pair in the request specific data.

[ GitHub ]

  
# File 'lib/rack/request.rb', line 111

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

#fetch_header(name, &block)

If a block is given, it yields to the block if the value hasn’t been set on the request.

[ GitHub ]

  
# File 'lib/rack/request.rb', line 106

def fetch_header(name, &block)
  @env.fetch(name, &block)
end

#get_header(name)

Get a request specific value for name.

[ GitHub ]

  
# File 'lib/rack/request.rb', line 100

def get_header(name)
  @env[name]
end

#has_header?(name) ⇒ Boolean

Predicate method to test to see if name has been set as request specific data

[ GitHub ]

  
# File 'lib/rack/request.rb', line 95

def has_header?(name)
  @env.key? name
end

#initialize(env)

[ GitHub ]

  
# File 'lib/rack/request.rb', line 86

def initialize(env)
  @env = env
  # This module is included at least in `ActionDispatch::Request`
  # The call to `super()` allows additional mixed-in initializers are called
  super()
end

#initialize_copy(other)

[ GitHub ]

  
# File 'lib/rack/request.rb', line 144

def initialize_copy(other)
  @env = other.env.dup
end

#set_header(name, v)

Set a request specific value for name to ‘v`

[ GitHub ]

  
# File 'lib/rack/request.rb', line 116

def set_header(name, v)
  @env[name] = v
end