Module: Rack::Response::Helpers
| Relationships & Source Files | |
| Extension / Inclusion / Inheritance Descendants | |
| Included In: | |
| Defined in: | lib/rack/response.rb | 
Instance Attribute Summary
- #accepted? ⇒ Boolean readonly
- #bad_request? ⇒ Boolean readonly
- #cache_control rw
- #cache_control=(value) rw
- #client_error? ⇒ Boolean readonly
- 
    
      #content_type  
    
    rw
    Get the content type of the response. 
- 
    
      #content_type=(content_type)  
    
    rw
    Set the content type of the response. 
- #created? ⇒ Boolean readonly
- #etag rw
- #etag=(value) rw
- #forbidden? ⇒ Boolean readonly
- #informational? ⇒ Boolean readonly
- #invalid? ⇒ Boolean readonly
- #location rw
- #location=(location) rw
- #method_not_allowed? ⇒ Boolean readonly
- #moved_permanently? ⇒ Boolean readonly
- #no_content? ⇒ Boolean readonly
- #not_acceptable? ⇒ Boolean readonly
- #not_found? ⇒ Boolean readonly
- #ok? ⇒ Boolean readonly
- #precondition_failed? ⇒ Boolean readonly
- #redirect? ⇒ Boolean readonly
- #redirection? ⇒ Boolean readonly
- #request_timeout? ⇒ Boolean readonly
- #server_error? ⇒ Boolean readonly
- #set_cookie_header rw
- #set_cookie_header=(value) rw
- #successful? ⇒ Boolean readonly
- #unauthorized? ⇒ Boolean readonly
- #unprocessable? ⇒ Boolean readonly
Instance Method Summary
- 
    
      #add_header(key, value)  
    
    Add a header that may have multiple values. 
- 
    
      #cache!(duration = 3600, directive: "public")  
    
    Specify that the content should be cached. 
- #content_length
- #delete_cookie(key, value = {})
- 
    
      #do_not_cache!  
    
    Specifies that the content shouldn’t be cached. 
- #include?(header) ⇒ Boolean
- #media_type
- #media_type_params
- #set_cookie(key, value)
Instance Attribute Details
    #accepted?  ⇒ Boolean  (readonly)
  
  [ GitHub ]
# File 'lib/rack/response.rb', line 191
def accepted?; status == 202; end
    #bad_request?  ⇒ Boolean  (readonly)
  
  [ GitHub ]
# File 'lib/rack/response.rb', line 194
def bad_request?; status == 400; end
#cache_control (rw)
[ GitHub ]# File 'lib/rack/response.rb', line 290
def cache_control get_header CACHE_CONTROL end
#cache_control=(value) (rw)
[ GitHub ]# File 'lib/rack/response.rb', line 294
def cache_control=(value) set_header CACHE_CONTROL, value end
    #client_error?  ⇒ Boolean  (readonly)
  
  [ GitHub ]
#content_type (rw)
Get the content type of the response.
# File 'lib/rack/response.rb', line 240
def content_type get_header CONTENT_TYPE end
#content_type=(content_type) (rw)
Set the content type of the response.
# File 'lib/rack/response.rb', line 245
def content_type=(content_type) set_header CONTENT_TYPE, content_type end
    #created?  ⇒ Boolean  (readonly)
  
  [ GitHub ]
# File 'lib/rack/response.rb', line 190
def created?; status == 201; end
#etag (rw)
[ GitHub ]# File 'lib/rack/response.rb', line 314
def etag get_header ETAG end
#etag=(value) (rw)
[ GitHub ]# File 'lib/rack/response.rb', line 318
def etag=(value) set_header ETAG, value end
    #forbidden?  ⇒ Boolean  (readonly)
  
  [ GitHub ]
# File 'lib/rack/response.rb', line 196
def forbidden?; status == 403; end
    #informational?  ⇒ Boolean  (readonly)
  
  [ GitHub ]
    #invalid?  ⇒ Boolean  (readonly)
  
  [ GitHub ]
#location (rw)
[ GitHub ]# File 'lib/rack/response.rb', line 262
def location get_header "location" end
#location=(location) (rw)
[ GitHub ]# File 'lib/rack/response.rb', line 266
def location=(location) set_header "location", location end
    #method_not_allowed?  ⇒ Boolean  (readonly)
  
  [ GitHub ]
# File 'lib/rack/response.rb', line 198
def method_not_allowed?; status == 405; end
    #moved_permanently?  ⇒ Boolean  (readonly)
  
  [ GitHub ]
# File 'lib/rack/response.rb', line 193
def moved_permanently?; status == 301; end
    #no_content?  ⇒ Boolean  (readonly)
  
  [ GitHub ]
# File 'lib/rack/response.rb', line 192
def no_content?; status == 204; end
    #not_acceptable?  ⇒ Boolean  (readonly)
  
  [ GitHub ]
# File 'lib/rack/response.rb', line 199
def not_acceptable?; status == 406; end
    #not_found?  ⇒ Boolean  (readonly)
  
  [ GitHub ]
# File 'lib/rack/response.rb', line 197
def not_found?; status == 404; end
    #ok?  ⇒ Boolean  (readonly)
  
  [ GitHub ]
# File 'lib/rack/response.rb', line 189
def ok?; status == 200; end
    #precondition_failed?  ⇒ Boolean  (readonly)
  
  [ GitHub ]
# File 'lib/rack/response.rb', line 201
def precondition_failed?; status == 412; end
    #redirect?  ⇒ Boolean  (readonly)
  
  [ GitHub ]
    #redirection?  ⇒ Boolean  (readonly)
  
  [ GitHub ]
    #request_timeout?  ⇒ Boolean  (readonly)
  
  [ GitHub ]
# File 'lib/rack/response.rb', line 200
def request_timeout?; status == 408; end
    #server_error?  ⇒ Boolean  (readonly)
  
  [ GitHub ]
#set_cookie_header (rw)
[ GitHub ]# File 'lib/rack/response.rb', line 282
def get_header SET_COOKIE end
#set_cookie_header=(value) (rw)
[ GitHub ]# File 'lib/rack/response.rb', line 286
def (value) set_header SET_COOKIE, value end
    #successful?  ⇒ Boolean  (readonly)
  
  [ GitHub ]
    #unauthorized?  ⇒ Boolean  (readonly)
  
  [ GitHub ]
# File 'lib/rack/response.rb', line 195
def ; status == 401; end
    #unprocessable?  ⇒ Boolean  (readonly)
  
  [ GitHub ]
# File 'lib/rack/response.rb', line 202
def unprocessable?; status == 422; end
Instance Method Details
#add_header(key, value)
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')# File 'lib/rack/response.rb', line 219
def add_header(key, value) raise ArgumentError unless key.is_a?(String) if value.nil? return get_header(key) end value = value.to_s if header = get_header(key) if header.is_a?(Array) header << value else set_header(key, [header, value]) end else set_header(key, value) end end
#cache!(duration = 3600, directive: "public")
Specify that the content should be cached.
# File 'lib/rack/response.rb', line 307
def cache!(duration = 3600, directive: "public") unless headers[CACHE_CONTROL] =~ /no-cache/ set_header CACHE_CONTROL, "#{directive}, max-age=#{duration}" set_header EXPIRES, (Time.now + duration).httpdate end end
#content_length
[ GitHub ]# File 'lib/rack/response.rb', line 257
def content_length cl = get_header CONTENT_LENGTH cl ? cl.to_i : cl end
#delete_cookie(key, value = {})
[ GitHub ]# File 'lib/rack/response.rb', line 274
def (key, value = {}) set_header(SET_COOKIE, Utils.( get_header(SET_COOKIE), key, value ) ) end
#do_not_cache!
Specifies that the content shouldn’t be cached. Overrides #cache! if already called.
# File 'lib/rack/response.rb', line 299
def do_not_cache! set_header CACHE_CONTROL, "no-cache, must-revalidate" set_header EXPIRES, Time.now.httpdate end
    #include?(header)  ⇒ Boolean 
  
# File 'lib/rack/response.rb', line 206
def include?(header) has_header?(header) end
#media_type
[ GitHub ]# File 'lib/rack/response.rb', line 249
def media_type MediaType.type(content_type) end
#media_type_params
[ GitHub ]# File 'lib/rack/response.rb', line 253
def media_type_params MediaType.params(content_type) end
#set_cookie(key, value)
[ GitHub ]# File 'lib/rack/response.rb', line 270
def (key, value) add_header SET_COOKIE, Utils.(key, value) end