aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorNicholas Seckar <nseckar@gmail.com>2006-03-18 16:45:40 +0000
committerNicholas Seckar <nseckar@gmail.com>2006-03-18 16:45:40 +0000
commit240213177eba35921f9ee621e8865311b94f6d21 (patch)
tree90efeb000fab14fef91ccaf7b28663915ab2b934 /actionpack
parentfddd33b81e1261f89b2c02368c43d38eb0206170 (diff)
downloadrails-240213177eba35921f9ee621e8865311b94f6d21.tar.gz
rails-240213177eba35921f9ee621e8865311b94f6d21.tar.bz2
rails-240213177eba35921f9ee621e8865311b94f6d21.zip
Add ability for relative_url_root to be specified via an environment variable RAILS_RELATIVE_URL_ROOT. Closes #4243.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3931 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG2
-rwxr-xr-xactionpack/lib/action_controller/request.rb13
-rw-r--r--actionpack/test/controller/request_test.rb13
3 files changed, 26 insertions, 2 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 07dc50d398..2aff18340b 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Add ability for relative_url_root to be specified via an environment variable RAILS_RELATIVE_URL_ROOT. [isaac@reuben.com, Nicholas Seckar]
+
* Fixed link_to "somewhere", :post => true to produce valid XHTML by using the parentnode instead of document.body for the instant form #3007 [Bob Silva]
* Added :function option to PrototypeHelper#observe_field/observe_form that allows you to call a function instead of submitting an ajax call as the trigger #4268 [jonathan@daikini.com]
diff --git a/actionpack/lib/action_controller/request.rb b/actionpack/lib/action_controller/request.rb
index 3bfc8f9385..566ae42ba0 100755
--- a/actionpack/lib/action_controller/request.rb
+++ b/actionpack/lib/action_controller/request.rb
@@ -163,9 +163,18 @@ module ActionController
end
# Returns the path minus the web server relative installation directory.
- # This method returns nil unless the web server is apache.
+ # This can be set with the environment variable RAILS_RELATIVE_URL_ROOT.
+ # It can be automatically extracted for Apache setups. If the server is not
+ # Apache, this method returns an empty string.
def relative_url_root
- @@relative_url_root ||= server_software == 'apache' ? @env["SCRIPT_NAME"].to_s.sub(/\/dispatch\.(fcgi|rb|cgi)$/, '') : ''
+ @@relative_url_root ||= case
+ when @env["RAILS_RELATIVE_URL_ROOT"]
+ @env["RAILS_RELATIVE_URL_ROOT"]
+ when server_software == 'apache'
+ @env["SCRIPT_NAME"].to_s.sub(/\/dispatch\.(fcgi|rb|cgi)$/, '')
+ else
+ ''
+ end
end
# Returns the port number of this request as an integer.
diff --git a/actionpack/test/controller/request_test.rb b/actionpack/test/controller/request_test.rb
index a7623f3403..43cd8836fe 100644
--- a/actionpack/test/controller/request_test.rb
+++ b/actionpack/test/controller/request_test.rb
@@ -105,6 +105,19 @@ class RequestTest < Test::Unit::TestCase
@request.relative_url_root = nil
@request.env['SCRIPT_NAME'] = "/collaboration/hieraki"
assert_equal "/collaboration/hieraki", @request.relative_url_root
+
+ @request.relative_url_root = nil
+ @request.env['SCRIPT_NAME'] = "/hieraki/dispatch.cgi"
+ @request.env['SERVER_SOFTWARE'] = 'lighttpd/1.2.3'
+ @request.env['RAILS_RELATIVE_URL_ROOT'] = "/hieraki"
+ assert_equal "/hieraki", @request.relative_url_root
+
+ # @env overrides path guess
+ @request.relative_url_root = nil
+ @request.env['SCRIPT_NAME'] = "/hieraki/dispatch.cgi"
+ @request.env['SERVER_SOFTWARE'] = 'apache/1.2.3 some random text'
+ @request.env['RAILS_RELATIVE_URL_ROOT'] = "/real_url"
+ assert_equal "/real_url", @request.relative_url_root
end
def test_request_uri