Module: Rack::Request::Env
- Included in:
- Rack::Request
- Defined in:
- lib/rack/request.rb
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
The environment of the request.
Instance Method Summary collapse
-
#add_header(key, v) ⇒ Object
Add a header that may have multiple values.
-
#delete_header(name) ⇒ Object
Delete a request specific value for ‘name`.
-
#each_header(&block) ⇒ Object
Loops through each key / value pair in the request specific data.
-
#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.
-
#get_header(name) ⇒ Object
Get a request specific value for ‘name`.
-
#has_header?(name) ⇒ Boolean
Predicate method to test to see if ‘name` has been set as request specific data.
- #initialize(env) ⇒ Object
- #initialize_copy(other) ⇒ Object
-
#set_header(name, v) ⇒ Object
Set a request specific value for ‘name` to `v`.
Instance Attribute Details
#env ⇒ Object (readonly)
The environment of the request.
53 54 55 |
# File 'lib/rack/request.rb', line 53 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')
96 97 98 99 100 101 102 103 104 |
# File 'lib/rack/request.rb', line 96 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`.
107 108 109 |
# File 'lib/rack/request.rb', line 107 def delete_header(name) @env.delete name end |
#each_header(&block) ⇒ Object
Loops through each key / value pair in the request specific data.
78 79 80 |
# File 'lib/rack/request.rb', line 78 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.
73 74 75 |
# File 'lib/rack/request.rb', line 73 def fetch_header(name, &block) @env.fetch(name, &block) end |
#get_header(name) ⇒ Object
Get a request specific value for ‘name`.
67 68 69 |
# File 'lib/rack/request.rb', line 67 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
62 63 64 |
# File 'lib/rack/request.rb', line 62 def has_header?(name) @env.key? name end |
#initialize(env) ⇒ Object
55 56 57 58 |
# File 'lib/rack/request.rb', line 55 def initialize(env) @env = env super() end |
#initialize_copy(other) ⇒ Object
111 112 113 |
# File 'lib/rack/request.rb', line 111 def initialize_copy(other) @env = other.env.dup end |
#set_header(name, v) ⇒ Object
Set a request specific value for ‘name` to `v`
83 84 85 |
# File 'lib/rack/request.rb', line 83 def set_header(name, v) @env[name] = v end |