Module: Rack::Request::Env

Included in:
Rack::Request
Defined in:
lib/rack/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#envObject (readonly)

The environment of the request.



36
37
38
# File 'lib/rack/request.rb', line 36

def env
  @env
end

Instance Method Details

#add_header(key, v) ⇒ Object

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



79
80
81
82
83
84
85
86
87
# File 'lib/rack/request.rb', line 79

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) ⇒ Object

Delete a request specific value for ‘name`.



90
91
92
# File 'lib/rack/request.rb', line 90

def delete_header(name)
  @env.delete name
end

#each_header(&block) ⇒ Object

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



61
62
63
# File 'lib/rack/request.rb', line 61

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

#fetch_header(name, &block) ⇒ Object

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



56
57
58
# File 'lib/rack/request.rb', line 56

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

#get_header(name) ⇒ Object

Get a request specific value for ‘name`.



50
51
52
# File 'lib/rack/request.rb', line 50

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

Returns:

  • (Boolean)


45
46
47
# File 'lib/rack/request.rb', line 45

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

#initialize(env) ⇒ Object



38
39
40
41
# File 'lib/rack/request.rb', line 38

def initialize(env)
  @env = env
  super()
end

#initialize_copy(other) ⇒ Object



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

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

#set_header(name, v) ⇒ Object

Set a request specific value for ‘name` to `v`



66
67
68
# File 'lib/rack/request.rb', line 66

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