Permalink
Browse files

Added :host and :protocol options to url_for and friends to redirect …

…to another host and protocol than the current.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@266 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
dhh committed Dec 23, 2004
1 parent 8e41326 commit 00deaf6d56085d4961eff8e8e0948a9241dfd5ea
View
@@ -1,3 +1,8 @@
+*SVN*
+
+* Added :host and :protocol options to url_for and friends to redirect to another host and protocol than the current.
+
+
*1.1.0*
* Added search through session to clear out association caches at the end of each request. This makes it possible to place Active Record objects
@@ -1,7 +1,7 @@
module ActionController
# Rewrites urls for Base.redirect_to and Base.url_for in the controller.
class UrlRewriter #:nodoc:
- VALID_OPTIONS = [:action, :action_prefix, :action_suffix, :module, :controller, :controller_prefix, :anchor, :params, :path_params, :id, :only_path, :overwrite_params ]
+ VALID_OPTIONS = [:action, :action_prefix, :action_suffix, :module, :controller, :controller_prefix, :anchor, :params, :path_params, :id, :only_path, :overwrite_params, :host, :protocol ]
def initialize(request, controller, action)
@request, @controller, @action = request, controller, action
@@ -38,8 +38,8 @@ def resolve_aliases(options)
def rewrite_url(path, options)
rewritten_url = ""
- rewritten_url << @request.protocol unless options[:only_path]
- rewritten_url << @request.host_with_port unless options[:only_path]
+ rewritten_url << (options[:protocol] || @request.protocol) unless options[:only_path]
+ rewritten_url << (options[:host] || @request.host_with_port) unless options[:only_path]
rewritten_url << path
rewritten_url << build_query_string(new_parameters(options)) if options[:params] || options[:overwrite_params]
@@ -60,6 +60,20 @@ def test_clean_action
assert_equal "http://www.singlefile.com/library/books/ISBN/0743536703/edit", @library_url.rewrite(:action => "edit")
end
+ def test_clean_action_to_another_host
+ assert_equal(
+ "http://www.booksphere.com/library/books/ISBN/0743536703/edit",
+ @library_url.rewrite(:action => "edit", :host => "www.booksphere.com")
+ )
+ end
+
+ def test_clean_action_to_another_host_and_protocol
+ assert_equal(
+ "https://www.booksphere.com/library/books/ISBN/0743536703/edit",
+ @library_url.rewrite(:action => "edit", :host => "www.booksphere.com", :protocol => "https://")
+ )
+ end
+
def test_clean_action_with_only_path
assert_equal "/library/books/ISBN/0743536703/edit", @library_url.rewrite(:action => "edit", :only_path => true)
end

0 comments on commit 00deaf6

Please sign in to comment.