use url helper for redirects, make redirects configurable, fixes #183

This commit is contained in:
Konstantin Haase 2011-02-19 11:26:33 +01:00
parent 4248e6dde2
commit c835bdd78e
1 changed files with 7 additions and 14 deletions

View File

@ -91,21 +91,11 @@ module Sinatra
# Halt processing and redirect to the URI provided.
def redirect(uri, *args)
if not uri =~ /^https?:\/\//
# According to RFC 2616 section 14.30, "the field value consists of a
# single absolute URI"
abs_uri = "#{request.scheme}://#{request.host}"
if request.scheme == 'https' && request.port != 443 ||
request.scheme == 'http' && request.port != 80
abs_uri << ":#{request.port}"
end
uri = (abs_uri << uri)
end
status 302
response['Location'] = uri
# According to RFC 2616 section 14.30, "the field value consists of a
# single absolute URI"
response['Location'] = url(uri, absolute_redirects?, settings.prefixed_redirects?)
halt(*args)
end
@ -1305,6 +1295,9 @@ module Sinatra
set :bind, '0.0.0.0'
set :port, 4567
set :absolute_redirects, true
set :prefixed_redirects, false
set :app_file, nil
set :root, Proc.new { app_file && File.expand_path(File.dirname(app_file)) }
set :views, Proc.new { root && File.join(root, 'views') }