Method: Sinatra::Helpers#redirect
- Defined in:
- lib/sinatra/base.rb
#redirect(uri, *args) ⇒ Object
Halt processing and redirect to the URI provided.
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
# File 'lib/sinatra/base.rb', line 310 def redirect(uri, *args) # SERVER_PROTOCOL is required in Rack 3, fall back to HTTP_VERSION # for servers not updated for Rack 3 (like Puma 5) http_version = env['SERVER_PROTOCOL'] || env['HTTP_VERSION'] if (http_version == 'HTTP/1.1') && (env['REQUEST_METHOD'] != 'GET') status 303 else status 302 end # According to RFC 2616 section 14.30, "the field value consists of a # single absolute URI" response['Location'] = uri(uri.to_s, settings.absolute_redirects?, settings.prefixed_redirects?) halt(*args) end |