aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG6
-rwxr-xr-xactionpack/lib/action_controller/request.rb17
-rw-r--r--actionpack/test/controller/request_test.rb17
3 files changed, 33 insertions, 7 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index d06a89af90..34011c66d5 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,8 +1,8 @@
*SVN*
-* Correct distance_of_time_in_words for integer arguments and make the second ar
-g optional, treating the first arg as a duration in seconds. #1458 [madrobby <t
-homas@fesch.at>]
+* Fixed relative urls support for lighttpd #1048 [Nicholas Seckar/maznawak@nerim.net]
+
+* Correct distance_of_time_in_words for integer arguments and make the second arg optional, treating the first arg as a duration in seconds. #1458 [madrobby <thomas@fesch.at>]
* Fixed query parser to deal gracefully with equal signs inside keys and values #1345 [gorou].
Example: /?sig=abcdef=:foobar=&x=y will pass now.
diff --git a/actionpack/lib/action_controller/request.rb b/actionpack/lib/action_controller/request.rb
index 2cb4377273..73247d510a 100755
--- a/actionpack/lib/action_controller/request.rb
+++ b/actionpack/lib/action_controller/request.rb
@@ -135,12 +135,17 @@ module ActionController
# Returns the interpreted path to requested resource after all the installation directory of this application was taken into account
def path
path = (uri = request_uri) ? uri.split('?').first : ''
- path[relative_url_root.length..-1] # cut off the part of the url which leads to the installation directory of this app
+
+ # Cut off the path to the installation directory if given
+ if (root = relative_url_root) then path[root.length..-1]
+ else path
+ end
end
- # Returns the path minus the web server relative installation directory
- def relative_url_root(force_reload = false)
- @@relative_url_root ||= File.dirname(env["SCRIPT_NAME"].to_s).gsub(/(^\.$|^\/$)/, '')
+ # Returns the path minus the web server relative installation directory.
+ # This method returns nil unless the web server is apache.
+ def relative_url_root
+ @@relative_url_root ||= File.dirname(env["SCRIPT_NAME"].to_s).gsub(/(^\.$|^\/$)/, '') if server_software == 'apache'
end
def port
@@ -165,6 +170,10 @@ module ActionController
@path_parameters ||= {}
end
+ def server_software
+ (env['SERVER_SOFTWARE'] && /^([a-zA-Z]+)/ =~ env['SERVER_SOFTWARE']) ? $1.downcase : nil
+ end
+
#--
# Must be implemented in the concrete request
#++
diff --git a/actionpack/test/controller/request_test.rb b/actionpack/test/controller/request_test.rb
index 9678e5629b..dd7c9f9d84 100644
--- a/actionpack/test/controller/request_test.rb
+++ b/actionpack/test/controller/request_test.rb
@@ -66,6 +66,11 @@ class RequestTest < Test::Unit::TestCase
end
def test_relative_url_root
+ @request.env['SERVER_SOFTWARE'] = 'lighttpd/1.2.3'
+ assert_nil @request.relative_url_root, "relative_url_root should be disabled on lighttpd"
+
+ @request.env['SERVER_SOFTWARE'] = 'apache/1.2.3 some random text'
+
@request.env['SCRIPT_NAME'] = nil
assert_equal "", @request.relative_url_root
@@ -85,6 +90,8 @@ class RequestTest < Test::Unit::TestCase
end
def test_request_uri
+ @request.env['SERVER_SOFTWARE'] = 'Apache 42.342.3432'
+
@request.relative_url_root = nil
@request.set_REQUEST_URI "http://www.rubyonrails.org/path/of/some/uri?mapped=1"
assert_equal "/path/of/some/uri?mapped=1", @request.request_uri
@@ -193,4 +200,14 @@ class RequestTest < Test::Unit::TestCase
@request.port = 81
assert_equal "rubyonrails.org:81", @request.host_with_port
end
+
+ def test_server_software
+ assert_equal nil, @request.server_software
+
+ @request.env['SERVER_SOFTWARE'] = 'Apache3.422'
+ assert_equal 'apache', @request.server_software
+
+ @request.env['SERVER_SOFTWARE'] = 'lighttpd(1.1.4)'
+ assert_equal 'lighttpd', @request.server_software
+ end
end