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!(duration = 3600, directive: "public")  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Specify that the content should be cached.
 - #cache_control ⇒ Object
 - #cache_control=(v) ⇒ Object
 - #client_error? ⇒ Boolean
 - #content_length ⇒ Object
 - 
  
    
      #content_type  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Get the content type of the response.
 - 
  
    
      #content_type=(content_type)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Set the content type of the response.
 - #created? ⇒ Boolean
 - #delete_cookie(key, value = {}) ⇒ Object
 - 
  
    
      #do_not_cache!  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Specifies that the content shouldn't be cached.
 - #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
      145  | 
    
      # File 'lib/rack/response.rb', line 145 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')
  
      171 172 173 174 175 176 177 178 179  | 
    
      # File 'lib/rack/response.rb', line 171 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
      148  | 
    
      # File 'lib/rack/response.rb', line 148 def bad_request?; status == 400; end  | 
  
#cache!(duration = 3600, directive: "public") ⇒ Object
Specify that the content should be cached.
      246 247 248 249 250 251  | 
    
      # File 'lib/rack/response.rb', line 246 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  | 
  
#cache_control ⇒ Object
      229 230 231  | 
    
      # File 'lib/rack/response.rb', line 229 def cache_control get_header CACHE_CONTROL end  | 
  
#cache_control=(v) ⇒ Object
      233 234 235  | 
    
      # File 'lib/rack/response.rb', line 233 def cache_control=(v) set_header CACHE_CONTROL, v end  | 
  
#client_error? ⇒ Boolean
      140  | 
    
      # File 'lib/rack/response.rb', line 140 def client_error?; status >= 400 && status < 500; end  | 
  
#content_length ⇒ Object
      199 200 201 202  | 
    
      # File 'lib/rack/response.rb', line 199 def content_length cl = get_header CONTENT_LENGTH cl ? cl.to_i : cl end  | 
  
#content_type ⇒ Object
Get the content type of the response.
      182 183 184  | 
    
      # File 'lib/rack/response.rb', line 182 def content_type get_header CONTENT_TYPE end  | 
  
#content_type=(content_type) ⇒ Object
Set the content type of the response.
      187 188 189  | 
    
      # File 'lib/rack/response.rb', line 187 def content_type=(content_type) set_header CONTENT_TYPE, content_type end  | 
  
#created? ⇒ Boolean
      144  | 
    
      # File 'lib/rack/response.rb', line 144 def created?; status == 201; end  | 
  
#delete_cookie(key, value = {}) ⇒ Object
      217 218 219  | 
    
      # File 'lib/rack/response.rb', line 217 def (key, value = {}) set_header SET_COOKIE, ::Rack::Utils.(get_header(SET_COOKIE), key, value) end  | 
  
#do_not_cache! ⇒ Object
Specifies that the content shouldn't be cached. Overrides `cache!` if already called.
      238 239 240 241  | 
    
      # File 'lib/rack/response.rb', line 238 def do_not_cache! set_header CACHE_CONTROL, "no-cache, must-revalidate" set_header EXPIRES, Time.now.httpdate end  | 
  
#etag ⇒ Object
      253 254 255  | 
    
      # File 'lib/rack/response.rb', line 253 def etag get_header ETAG end  | 
  
#etag=(v) ⇒ Object
      257 258 259  | 
    
      # File 'lib/rack/response.rb', line 257 def etag=(v) set_header ETAG, v end  | 
  
#forbidden? ⇒ Boolean
      150  | 
    
      # File 'lib/rack/response.rb', line 150 def forbidden?; status == 403; end  | 
  
#include?(header) ⇒ Boolean
      158 159 160  | 
    
      # File 'lib/rack/response.rb', line 158 def include?(header) has_header? header end  | 
  
#informational? ⇒ Boolean
      137  | 
    
      # File 'lib/rack/response.rb', line 137 def informational?; status >= 100 && status < 200; end  | 
  
#invalid? ⇒ Boolean
      135  | 
    
      # File 'lib/rack/response.rb', line 135 def invalid?; status < 100 || status >= 600; end  | 
  
#location ⇒ Object
      204 205 206  | 
    
      # File 'lib/rack/response.rb', line 204 def location get_header "Location" end  | 
  
#location=(location) ⇒ Object
      208 209 210  | 
    
      # File 'lib/rack/response.rb', line 208 def location=(location) set_header "Location", location end  | 
  
#media_type ⇒ Object
      191 192 193  | 
    
      # File 'lib/rack/response.rb', line 191 def media_type MediaType.type(content_type) end  | 
  
#media_type_params ⇒ Object
      195 196 197  | 
    
      # File 'lib/rack/response.rb', line 195 def media_type_params MediaType.params(content_type) end  | 
  
#method_not_allowed? ⇒ Boolean
      152  | 
    
      # File 'lib/rack/response.rb', line 152 def method_not_allowed?; status == 405; end  | 
  
#moved_permanently? ⇒ Boolean
      147  | 
    
      # File 'lib/rack/response.rb', line 147 def moved_permanently?; status == 301; end  | 
  
#no_content? ⇒ Boolean
      146  | 
    
      # File 'lib/rack/response.rb', line 146 def no_content?; status == 204; end  | 
  
#not_found? ⇒ Boolean
      151  | 
    
      # File 'lib/rack/response.rb', line 151 def not_found?; status == 404; end  | 
  
#ok? ⇒ Boolean
      143  | 
    
      # File 'lib/rack/response.rb', line 143 def ok?; status == 200; end  | 
  
#precondition_failed? ⇒ Boolean
      153  | 
    
      # File 'lib/rack/response.rb', line 153 def precondition_failed?; status == 412; end  | 
  
#redirect? ⇒ Boolean
      156  | 
    
      # File 'lib/rack/response.rb', line 156 def redirect?; [301, 302, 303, 307, 308].include? status; end  | 
  
#redirection? ⇒ Boolean
      139  | 
    
      # File 'lib/rack/response.rb', line 139 def redirection?; status >= 300 && status < 400; end  | 
  
#server_error? ⇒ Boolean
      141  | 
    
      # File 'lib/rack/response.rb', line 141 def server_error?; status >= 500 && status < 600; end  | 
  
#set_cookie(key, value) ⇒ Object
      212 213 214 215  | 
    
      # File 'lib/rack/response.rb', line 212 def (key, value) = get_header SET_COOKIE set_header SET_COOKIE, ::Rack::Utils.(, key, value) end  | 
  
#set_cookie_header ⇒ Object
      221 222 223  | 
    
      # File 'lib/rack/response.rb', line 221 def get_header SET_COOKIE end  | 
  
#set_cookie_header=(v) ⇒ Object
      225 226 227  | 
    
      # File 'lib/rack/response.rb', line 225 def (v) set_header SET_COOKIE, v end  | 
  
#successful? ⇒ Boolean
      138  | 
    
      # File 'lib/rack/response.rb', line 138 def successful?; status >= 200 && status < 300; end  | 
  
#unauthorized? ⇒ Boolean
      149  | 
    
      # File 'lib/rack/response.rb', line 149 def ; status == 401; end  | 
  
#unprocessable? ⇒ Boolean
      154  | 
    
      # File 'lib/rack/response.rb', line 154 def unprocessable?; status == 422; end  |