Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 6235

Show
Ignore:
Timestamp:
02/25/07 20:22:09 (2 years ago)
Author:
david
Message:

Added :port and :host handling to UrlRewriter (which unified url_for usage, regardless of whether it's called in view or controller) #7616 [alancfrancis]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r6233 r6235  
    11*SVN* 
     2 
     3* Added :port and :host handling to UrlRewriter (which unified url_for usage, regardless of whether it's called in view or controller) #7616 [alancfrancis] 
    24 
    35* Allow send_file/send_data to use a registered mime type as the :type parameter #7620 [jonathan] 
  • trunk/actionpack/lib/action_controller/url_rewriter.rb

    r6053 r6235  
    4444      unless options.delete :only_path 
    4545        url << (options.delete(:protocol) || 'http') 
    46         url << '://' 
     46        url << '://' unless url.match("://") #dont add separator if its already been specified in :protocol  
    4747         
    4848        raise "Missing host to link to! Please provide :host parameter or set default_url_options[:host]" unless options[:host] 
     
    6161  # Rewrites URLs for Base.redirect_to and Base.url_for in the controller. 
    6262  class UrlRewriter #:nodoc: 
    63     RESERVED_OPTIONS = [:anchor, :params, :only_path, :host, :protocol, :trailing_slash, :skip_relative_url_root] 
     63    RESERVED_OPTIONS = [:anchor, :params, :only_path, :host, :protocol, :port, :trailing_slash, :skip_relative_url_root] 
    6464    def initialize(request, parameters) 
    6565      @request, @parameters = request, parameters 
     
    8181        unless options[:only_path] 
    8282          rewritten_url << (options[:protocol] || @request.protocol) 
     83          rewritten_url << "://" unless rewritten_url.match("://") 
    8384          rewritten_url << (options[:host] || @request.host_with_port) 
     85          rewritten_url << ":#{options.delete(:port)}" if options.key?(:port) 
    8486        end 
    8587 
  • trunk/actionpack/test/controller/url_rewriter_test.rb

    r6053 r6235  
    88  end  
    99 
     10  def test_port 
     11    assert_equal('http://test.host:1271/c/a/i', 
     12      @rewriter.rewrite(:controller => 'c', :action => 'a', :id => 'i', :port => 1271) 
     13    ) 
     14  end 
     15 
     16  def test_protocol_with_and_without_separator 
     17    assert_equal('https://test.host/c/a/i', 
     18      @rewriter.rewrite(:protocol => 'https', :controller => 'c', :action => 'a', :id => 'i') 
     19    ) 
     20 
     21    assert_equal('https://test.host/c/a/i', 
     22      @rewriter.rewrite(:protocol => 'https://', :controller => 'c', :action => 'a', :id => 'i') 
     23    ) 
     24  end 
     25   
    1026  def test_overwrite_params 
    1127    @params[:controller] = 'hi' 
     
    86102  end 
    87103   
     104  def test_protocol_with_and_without_separator 
     105    add_host! 
     106    assert_equal('https://www.basecamphq.com/c/a/i', 
     107      W.new.url_for(:controller => 'c', :action => 'a', :id => 'i', :protocol => 'https') 
     108    ) 
     109    assert_equal('https://www.basecamphq.com/c/a/i', 
     110      W.new.url_for(:controller => 'c', :action => 'a', :id => 'i', :protocol => 'https://') 
     111    ) 
     112  end 
     113 
    88114  def test_named_route 
    89115    ActionController::Routing::Routes.draw do |map|