Module: Rack::Response::Helpers

Included in:
Rack::Response, Raw
Defined in:
lib/rack/response.rb

Instance Method Summary collapse

Instance Method Details

#accepted?Boolean


132
# File 'lib/rack/response.rb', line 132

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')

www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2


158
159
160
161
162
163
164
165
166
# File 'lib/rack/response.rb', line 158

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


135
# File 'lib/rack/response.rb', line 135

def bad_request?;         status == 400;                        end

#cache_controlObject


210
211
212
# File 'lib/rack/response.rb', line 210

def cache_control
  get_header CACHE_CONTROL
end

#cache_control=(v) ⇒ Object


214
215
216
# File 'lib/rack/response.rb', line 214

def cache_control= v
  set_header CACHE_CONTROL, v
end

#client_error?Boolean


127
# File 'lib/rack/response.rb', line 127

def client_error?;        status >= 400 && status < 500;        end

#content_lengthObject


180
181
182
183
# File 'lib/rack/response.rb', line 180

def content_length
  cl = get_header CONTENT_LENGTH
  cl ? cl.to_i : cl
end

#content_typeObject


168
169
170
# File 'lib/rack/response.rb', line 168

def content_type
  get_header CONTENT_TYPE
end

#created?Boolean


131
# File 'lib/rack/response.rb', line 131

def created?;             status == 201;                        end

198
199
200
# File 'lib/rack/response.rb', line 198

def delete_cookie(key, value = {})
  set_header SET_COOKIE, ::Rack::Utils.add_remove_cookie_to_header(get_header(SET_COOKIE), key, value)
end

#etagObject


218
219
220
# File 'lib/rack/response.rb', line 218

def etag
  get_header ETAG
end

#etag=(v) ⇒ Object


222
223
224
# File 'lib/rack/response.rb', line 222

def etag= v
  set_header ETAG, v
end

#forbidden?Boolean


137
# File 'lib/rack/response.rb', line 137

def forbidden?;           status == 403;                        end

#include?(header) ⇒ Boolean


145
146
147
# File 'lib/rack/response.rb', line 145

def include?(header)
  has_header? header
end

#informational?Boolean


124
# File 'lib/rack/response.rb', line 124

def informational?;       status >= 100 && status < 200;        end

#invalid?Boolean


122
# File 'lib/rack/response.rb', line 122

def invalid?;             status < 100 || status >= 600;        end

#locationObject


185
186
187
# File 'lib/rack/response.rb', line 185

def location
  get_header "Location"
end

#location=(location) ⇒ Object


189
190
191
# File 'lib/rack/response.rb', line 189

def location=(location)
  set_header "Location", location
end

#media_typeObject


172
173
174
# File 'lib/rack/response.rb', line 172

def media_type
  MediaType.type(content_type)
end

#media_type_paramsObject


176
177
178
# File 'lib/rack/response.rb', line 176

def media_type_params
  MediaType.params(content_type)
end

#method_not_allowed?Boolean


139
# File 'lib/rack/response.rb', line 139

def method_not_allowed?;  status == 405;                        end

#moved_permanently?Boolean


134
# File 'lib/rack/response.rb', line 134

def moved_permanently?;   status == 301;                        end

#no_content?Boolean


133
# File 'lib/rack/response.rb', line 133

def no_content?;          status == 204;                        end

#not_found?Boolean


138
# File 'lib/rack/response.rb', line 138

def not_found?;           status == 404;                        end

#ok?Boolean


130
# File 'lib/rack/response.rb', line 130

def ok?;                  status == 200;                        end

#precondition_failed?Boolean


140
# File 'lib/rack/response.rb', line 140

def precondition_failed?; status == 412;                        end

#redirect?Boolean


143
# File 'lib/rack/response.rb', line 143

def redirect?;            [301, 302, 303, 307, 308].include? status; end

#redirection?Boolean


126
# File 'lib/rack/response.rb', line 126

def redirection?;         status >= 300 && status < 400;        end

#server_error?Boolean


128
# File 'lib/rack/response.rb', line 128

def server_error?;        status >= 500 && status < 600;        end

193
194
195
196
# File 'lib/rack/response.rb', line 193

def set_cookie(key, value)
  cookie_header = get_header SET_COOKIE
  set_header SET_COOKIE, ::Rack::Utils.add_cookie_to_header(cookie_header, key, value)
end

202
203
204
# File 'lib/rack/response.rb', line 202

def set_cookie_header
  get_header SET_COOKIE
end

206
207
208
# File 'lib/rack/response.rb', line 206

def set_cookie_header= v
  set_header SET_COOKIE, v
end

#successful?Boolean


125
# File 'lib/rack/response.rb', line 125

def successful?;          status >= 200 && status < 300;        end

#unauthorized?Boolean


136
# File 'lib/rack/response.rb', line 136

def unauthorized?;        status == 401;                        end

#unprocessable?Boolean


141
# File 'lib/rack/response.rb', line 141

def unprocessable?;       status == 422;                        end