mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Set request.env['REQUEST_URI'] when absent.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5895 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
89b472aa0c
commit
fe736a54f9
2 changed files with 20 additions and 12 deletions
|
@ -145,19 +145,21 @@ module ActionController
|
||||||
@env['RAW_POST_DATA']
|
@env['RAW_POST_DATA']
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the request URI correctly, taking into account the idiosyncracies
|
# Return the request URI, accounting for server idiosyncracies.
|
||||||
# of the various servers.
|
# WEBrick includes the full URL. IIS leaves REQUEST_URI blank.
|
||||||
def request_uri
|
def request_uri
|
||||||
if uri = @env['REQUEST_URI']
|
if uri = @env['REQUEST_URI']
|
||||||
(%r{^\w+\://[^/]+(/.*|$)$} =~ uri) ? $1 : uri # Remove domain, which webrick puts into the request_uri.
|
# Remove domain, which webrick puts into the request_uri.
|
||||||
else # REQUEST_URI is blank under IIS - get this from PATH_INFO and SCRIPT_NAME
|
(%r{^\w+\://[^/]+(/.*|$)$} =~ uri) ? $1 : uri
|
||||||
|
else
|
||||||
|
# Construct IIS missing REQUEST_URI from SCRIPT_NAME and PATH_INFO.
|
||||||
script_filename = @env['SCRIPT_NAME'].to_s.match(%r{[^/]+$})
|
script_filename = @env['SCRIPT_NAME'].to_s.match(%r{[^/]+$})
|
||||||
uri = @env['PATH_INFO']
|
uri = @env['PATH_INFO']
|
||||||
uri = uri.sub(/#{script_filename}\//, '') unless script_filename.nil?
|
uri = uri.sub(/#{script_filename}\//, '') unless script_filename.nil?
|
||||||
unless (env_qs = @env['QUERY_STRING']).nil? || env_qs.empty?
|
unless (env_qs = @env['QUERY_STRING']).nil? || env_qs.empty?
|
||||||
uri << '?' << env_qs
|
uri << '?' << env_qs
|
||||||
end
|
end
|
||||||
uri
|
@env['REQUEST_URI'] = uri
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -174,48 +174,54 @@ class RequestTest < Test::Unit::TestCase
|
||||||
assert_equal "/path/of/some/uri?mapped=1", @request.request_uri
|
assert_equal "/path/of/some/uri?mapped=1", @request.request_uri
|
||||||
assert_equal "/path/of/some/uri", @request.path
|
assert_equal "/path/of/some/uri", @request.path
|
||||||
|
|
||||||
|
@request.set_REQUEST_URI nil
|
||||||
@request.relative_url_root = nil
|
@request.relative_url_root = nil
|
||||||
@request.env['PATH_INFO'] = "/path/of/some/uri?mapped=1"
|
@request.env['PATH_INFO'] = "/path/of/some/uri?mapped=1"
|
||||||
@request.env['SCRIPT_NAME'] = "/path/dispatch.rb"
|
@request.env['SCRIPT_NAME'] = "/path/dispatch.rb"
|
||||||
assert_equal "/path/of/some/uri?mapped=1", @request.request_uri
|
assert_equal "/path/of/some/uri?mapped=1", @request.request_uri
|
||||||
assert_equal "/of/some/uri", @request.path
|
assert_equal "/of/some/uri", @request.path
|
||||||
|
|
||||||
|
@request.set_REQUEST_URI nil
|
||||||
@request.relative_url_root = nil
|
@request.relative_url_root = nil
|
||||||
@request.env['PATH_INFO'] = "/path/of/some/uri"
|
@request.env['PATH_INFO'] = "/path/of/some/uri"
|
||||||
@request.env['SCRIPT_NAME'] = nil
|
@request.env['SCRIPT_NAME'] = nil
|
||||||
assert_equal "/path/of/some/uri", @request.request_uri
|
assert_equal "/path/of/some/uri", @request.request_uri
|
||||||
assert_equal "/path/of/some/uri", @request.path
|
assert_equal "/path/of/some/uri", @request.path
|
||||||
|
|
||||||
|
@request.set_REQUEST_URI nil
|
||||||
@request.relative_url_root = nil
|
@request.relative_url_root = nil
|
||||||
@request.env['PATH_INFO'] = "/"
|
@request.env['PATH_INFO'] = "/"
|
||||||
assert_equal "/", @request.request_uri
|
assert_equal "/", @request.request_uri
|
||||||
assert_equal "/", @request.path
|
assert_equal "/", @request.path
|
||||||
|
|
||||||
|
@request.set_REQUEST_URI nil
|
||||||
@request.relative_url_root = nil
|
@request.relative_url_root = nil
|
||||||
@request.env['PATH_INFO'] = "/?m=b"
|
@request.env['PATH_INFO'] = "/?m=b"
|
||||||
assert_equal "/?m=b", @request.request_uri
|
assert_equal "/?m=b", @request.request_uri
|
||||||
assert_equal "/", @request.path
|
assert_equal "/", @request.path
|
||||||
|
|
||||||
|
@request.set_REQUEST_URI nil
|
||||||
@request.relative_url_root = nil
|
@request.relative_url_root = nil
|
||||||
@request.env['PATH_INFO'] = "/"
|
@request.env['PATH_INFO'] = "/"
|
||||||
@request.env['SCRIPT_NAME'] = "/dispatch.cgi"
|
@request.env['SCRIPT_NAME'] = "/dispatch.cgi"
|
||||||
assert_equal "/", @request.request_uri
|
assert_equal "/", @request.request_uri
|
||||||
assert_equal "/", @request.path
|
assert_equal "/", @request.path
|
||||||
|
|
||||||
|
@request.set_REQUEST_URI nil
|
||||||
@request.relative_url_root = nil
|
@request.relative_url_root = nil
|
||||||
@request.env['PATH_INFO'] = "/hieraki/"
|
@request.env['PATH_INFO'] = "/hieraki/"
|
||||||
@request.env['SCRIPT_NAME'] = "/hieraki/dispatch.cgi"
|
@request.env['SCRIPT_NAME'] = "/hieraki/dispatch.cgi"
|
||||||
assert_equal "/hieraki/", @request.request_uri
|
assert_equal "/hieraki/", @request.request_uri
|
||||||
assert_equal "/", @request.path
|
assert_equal "/", @request.path
|
||||||
|
|
||||||
@request.set_REQUEST_URI '/hieraki/dispatch.cgi'
|
@request.set_REQUEST_URI '/hieraki/dispatch.cgi'
|
||||||
@request.relative_url_root = '/hieraki'
|
@request.relative_url_root = '/hieraki'
|
||||||
assert_equal "/dispatch.cgi", @request.path
|
assert_equal "/dispatch.cgi", @request.path
|
||||||
@request.relative_url_root = nil
|
@request.relative_url_root = nil
|
||||||
|
|
||||||
@request.set_REQUEST_URI '/hieraki/dispatch.cgi'
|
@request.set_REQUEST_URI '/hieraki/dispatch.cgi'
|
||||||
@request.relative_url_root = '/foo'
|
@request.relative_url_root = '/foo'
|
||||||
assert_equal "/hieraki/dispatch.cgi", @request.path
|
assert_equal "/hieraki/dispatch.cgi", @request.path
|
||||||
@request.relative_url_root = nil
|
@request.relative_url_root = nil
|
||||||
|
|
||||||
# This test ensures that Rails uses REQUEST_URI over PATH_INFO
|
# This test ensures that Rails uses REQUEST_URI over PATH_INFO
|
||||||
|
@ -226,7 +232,7 @@ class RequestTest < Test::Unit::TestCase
|
||||||
assert_equal "/some/path", @request.request_uri
|
assert_equal "/some/path", @request.request_uri
|
||||||
assert_equal "/some/path", @request.path
|
assert_equal "/some/path", @request.path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def test_host_with_port
|
def test_host_with_port
|
||||||
@request.host = "rubyonrails.org"
|
@request.host = "rubyonrails.org"
|
||||||
|
|
Loading…
Reference in a new issue