Module: Rack::Response::Helpers

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

Instance Method Summary collapse

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

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


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_controlObject


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_lengthObject


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_typeObject


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

187
188
189
# File 'lib/rack/response.rb', line 187

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

#etagObject


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

#locationObject


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_typeObject


161
162
163
# File 'lib/rack/response.rb', line 161

def media_type
  MediaType.type(content_type)
end

#media_type_paramsObject


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

182
183
184
185
# File 'lib/rack/response.rb', line 182

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

191
192
193
# File 'lib/rack/response.rb', line 191

def set_cookie_header
  get_header SET_COOKIE
end

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

def set_cookie_header= 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 unauthorized?;        status == 401;                        end

#unprocessable?Boolean


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

def unprocessable?;       status == 422;                        end