Module: Rack::Response::Helpers
- Included in:
- Rack::Response, Raw
- Defined in:
- lib/rack/response.rb
Instance Method Summary collapse
- #accepted? ⇒ Boolean
-
#add_header(key, v) ⇒ Object
Add a header that may have multiple values.
- #bad_request? ⇒ Boolean
- #cache_control ⇒ Object
- #cache_control=(v) ⇒ Object
- #client_error? ⇒ Boolean
- #content_length ⇒ Object
- #content_type ⇒ Object
- #created? ⇒ Boolean
- #delete_cookie(key, value = {}) ⇒ Object
- #etag ⇒ Object
- #etag=(v) ⇒ Object
- #forbidden? ⇒ Boolean
- #include?(header) ⇒ Boolean
- #informational? ⇒ Boolean
- #invalid? ⇒ Boolean
- #location ⇒ Object
- #location=(location) ⇒ Object
- #media_type ⇒ Object
- #media_type_params ⇒ Object
- #method_not_allowed? ⇒ Boolean
- #moved_permanently? ⇒ Boolean
- #no_content? ⇒ Boolean
- #not_found? ⇒ Boolean
- #ok? ⇒ Boolean
- #precondition_failed? ⇒ Boolean
- #redirect? ⇒ Boolean
- #redirection? ⇒ Boolean
- #server_error? ⇒ Boolean
- #set_cookie(key, value) ⇒ Object
- #set_cookie_header ⇒ Object
- #set_cookie_header=(v) ⇒ Object
- #successful? ⇒ Boolean
- #unauthorized? ⇒ Boolean
- #unprocessable? ⇒ Boolean
Instance Method Details
#accepted? ⇒ Boolean
121 |
# File 'lib/rack/response.rb', line 121 def accepted?; status == 202; end |
#add_header(key, v) ⇒ Object
Add a header that may have multiple values.
Example:
response.add_header 'Vary', 'Accept-Encoding'
response.add_header 'Vary', 'Cookie'
assert_equal 'Accept-Encoding,Cookie', response.get_header('Vary')
147 148 149 150 151 152 153 154 155 |
# File 'lib/rack/response.rb', line 147 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 |
#bad_request? ⇒ Boolean
124 |
# File 'lib/rack/response.rb', line 124 def bad_request?; status == 400; end |
#cache_control ⇒ Object
199 200 201 |
# File 'lib/rack/response.rb', line 199 def cache_control get_header CACHE_CONTROL end |
#cache_control=(v) ⇒ Object
203 204 205 |
# File 'lib/rack/response.rb', line 203 def cache_control= v set_header CACHE_CONTROL, v end |
#client_error? ⇒ Boolean
116 |
# File 'lib/rack/response.rb', line 116 def client_error?; status >= 400 && status < 500; end |
#content_length ⇒ Object
169 170 171 172 |
# File 'lib/rack/response.rb', line 169 def content_length cl = get_header CONTENT_LENGTH cl ? cl.to_i : cl end |
#content_type ⇒ Object
157 158 159 |
# File 'lib/rack/response.rb', line 157 def content_type get_header CONTENT_TYPE end |
#created? ⇒ Boolean
120 |
# File 'lib/rack/response.rb', line 120 def created?; status == 201; end |
#delete_cookie(key, value = {}) ⇒ Object
187 188 189 |
# File 'lib/rack/response.rb', line 187 def (key, value={}) set_header SET_COOKIE, ::Rack::Utils.(get_header(SET_COOKIE), key, value) end |
#etag ⇒ Object
207 208 209 |
# File 'lib/rack/response.rb', line 207 def etag get_header ETAG end |
#etag=(v) ⇒ Object
211 212 213 |
# File 'lib/rack/response.rb', line 211 def etag= v set_header ETAG, v end |
#forbidden? ⇒ Boolean
126 |
# File 'lib/rack/response.rb', line 126 def forbidden?; status == 403; end |
#include?(header) ⇒ Boolean
134 135 136 |
# File 'lib/rack/response.rb', line 134 def include?(header) has_header? header end |
#informational? ⇒ Boolean
113 |
# File 'lib/rack/response.rb', line 113 def informational?; status >= 100 && status < 200; end |
#invalid? ⇒ Boolean
111 |
# File 'lib/rack/response.rb', line 111 def invalid?; status < 100 || status >= 600; end |
#location ⇒ Object
174 175 176 |
# File 'lib/rack/response.rb', line 174 def location get_header "Location" end |
#location=(location) ⇒ Object
178 179 180 |
# File 'lib/rack/response.rb', line 178 def location=(location) set_header "Location", location end |
#media_type ⇒ Object
161 162 163 |
# File 'lib/rack/response.rb', line 161 def media_type MediaType.type(content_type) end |
#media_type_params ⇒ Object
165 166 167 |
# File 'lib/rack/response.rb', line 165 def media_type_params MediaType.params(content_type) end |
#method_not_allowed? ⇒ Boolean
128 |
# File 'lib/rack/response.rb', line 128 def method_not_allowed?; status == 405; end |
#moved_permanently? ⇒ Boolean
123 |
# File 'lib/rack/response.rb', line 123 def moved_permanently?; status == 301; end |
#no_content? ⇒ Boolean
122 |
# File 'lib/rack/response.rb', line 122 def no_content?; status == 204; end |
#not_found? ⇒ Boolean
127 |
# File 'lib/rack/response.rb', line 127 def not_found?; status == 404; end |
#ok? ⇒ Boolean
119 |
# File 'lib/rack/response.rb', line 119 def ok?; status == 200; end |
#precondition_failed? ⇒ Boolean
129 |
# File 'lib/rack/response.rb', line 129 def precondition_failed?; status == 412; end |
#redirect? ⇒ Boolean
132 |
# File 'lib/rack/response.rb', line 132 def redirect?; [301, 302, 303, 307, 308].include? status; end |
#redirection? ⇒ Boolean
115 |
# File 'lib/rack/response.rb', line 115 def redirection?; status >= 300 && status < 400; end |
#server_error? ⇒ Boolean
117 |
# File 'lib/rack/response.rb', line 117 def server_error?; status >= 500 && status < 600; end |
#set_cookie(key, value) ⇒ Object
182 183 184 185 |
# File 'lib/rack/response.rb', line 182 def (key, value) = get_header SET_COOKIE set_header SET_COOKIE, ::Rack::Utils.(, key, value) end |
#set_cookie_header ⇒ Object
191 192 193 |
# File 'lib/rack/response.rb', line 191 def get_header SET_COOKIE end |
#set_cookie_header=(v) ⇒ Object
195 196 197 |
# File 'lib/rack/response.rb', line 195 def v set_header SET_COOKIE, v end |
#successful? ⇒ Boolean
114 |
# File 'lib/rack/response.rb', line 114 def successful?; status >= 200 && status < 300; end |
#unauthorized? ⇒ Boolean
125 |
# File 'lib/rack/response.rb', line 125 def ; status == 401; end |
#unprocessable? ⇒ Boolean
130 |
# File 'lib/rack/response.rb', line 130 def unprocessable?; status == 422; end |