Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Leave default_asset_host_protocol unset

When default_asset_host_protocol is left as nil, it will use absolute protocols when a request is present, and relative protocols otherwise (eg in asset generation)

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
commit 0ce562c1f3a5812ab67faf0defedd46b580c47be 1 parent 6fd9c1d
@jdelStrother jdelStrother authored josevalim committed
View
2  actionpack/lib/sprockets/railtie.rb
@@ -9,8 +9,6 @@ module Sprockets
# TODO: Get rid of config.assets.enabled
class Railtie < ::Rails::Railtie
- config.action_controller.default_asset_host_protocol = :relative
-
rake_tasks do
load "sprockets/assets.rake"
end
View
22 railties/test/application/assets_test.rb
@@ -451,6 +451,28 @@ class ::PostsController < ActionController::Base ; end
assert_equal 0, files.length, "Expected application.js asset to be removed, but still exists"
end
+ test "asset urls should use the request's protocol by default" do
+ app_with_assets_in_view
+ add_to_config "config.asset_host = 'example.com'"
+ require "#{app_path}/config/environment"
+ class ::PostsController < ActionController::Base; end
+
+ get '/posts', {}, {'HTTPS'=>'off'}
+ assert_match('src="http://example.com/assets/application.js', last_response.body)
+ get '/posts', {}, {'HTTPS'=>'on'}
+ assert_match('src="https://example.com/assets/application.js', last_response.body)
+ end
+
+ test "asset urls should be protocol-relative if no request is in scope" do
+ app_file "app/assets/javascripts/image_loader.js.erb", 'var src="<%= image_path("rails.png") %>";'
+ add_to_config "config.assets.precompile = %w{image_loader.js}"
+ add_to_config "config.asset_host = 'example.com'"
+ precompile!
+
+ assert_match 'src="//example.com/assets/rails.png"', File.read("#{app_path}/public/assets/image_loader.js")
+ end
+
+
private
def app_with_assets_in_view
Please sign in to comment.
Something went wrong with that request. Please try again.