From c9260c556ca5e238225de23bf2fd2cf21400f8aa Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 18 Feb 2007 07:23:57 +0000 Subject: Add request protocol to asset host if not given. Prefer setting asset host as hostname only, no request protocol. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6162 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_view/helpers/asset_tag_helper.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'actionpack/lib/action_view') diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index 8d62f07b8c..850615632f 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -10,7 +10,7 @@ module ActionView # in your environment.rb. These methods do not verify the assets exist before # linking to them. # - # ActionController::Base.asset_host = "http://assets.example.com" + # ActionController::Base.asset_host = "assets.example.com" # image_tag("rails.png") # => Rails # stylesheet_include_tag("application") @@ -212,7 +212,8 @@ module ActionView # Add the .ext if not present. Return full URLs otherwise untouched. # Prefix with /dir/ if lacking a leading /. Account for relative URL # roots. Rewrite the asset path for cache-busting asset ids. Include - # a single or wildcarded asset host if configured. + # a single or wildcarded asset host, if configured, with the correct + # request protocol. def compute_public_path(source, dir, ext) source += ".#{ext}" if File.extname(source).blank? if source =~ %r{^[-a-z]+://} @@ -221,7 +222,13 @@ module ActionView source = "/#{dir}/#{source}" unless source[0] == ?/ source = "#{@controller.request.relative_url_root}#{source}" rewrite_asset_path!(source) - "#{compute_asset_host(source)}#{source}" + + host = compute_asset_host(source) + unless host.blank? or host =~ %r{^[-a-z]+://} + host = "#{@controller.request.protocol}#{host}" + end + + "#{host}#{source}" end end -- cgit v1.2.3