Ticket #10549: asset_hosts_proc_with_2nd_request_parameter.diff
| File asset_hosts_proc_with_2nd_request_parameter.diff, 7.8 kB (added by chuyeow, 6 months ago) |
|---|
-
actionpack/test/template/asset_tag_helper_test.rb
old new 34 34 @request = Class.new do 35 35 def relative_url_root() "" end 36 36 def protocol() 'http://' end 37 def ssl?() false end 38 def host_with_port() 'localhost' end 37 39 end.new 38 40 39 41 @controller.request = @request … … 248 250 end 249 251 250 252 def test_caching_javascript_include_tag_when_caching_on_with_proc_asset_host 251 ENV[ "RAILS_ASSET_ID"] = ""253 ENV['RAILS_ASSET_ID'] = '' 252 254 ActionController::Base.asset_host = Proc.new { |source| "http://a#{source.length}.example.com" } 253 255 ActionController::Base.perform_caching = true 254 256 … … 264 266 FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'scripts.js')) 265 267 end 266 268 269 def test_caching_javascript_include_tag_when_caching_on_with_2_argument_proc_asset_host 270 ENV['RAILS_ASSET_ID'] = '' 271 ActionController::Base.asset_host = Proc.new { |source, request| 272 if request.ssl? 273 "#{request.protocol}#{request.host_with_port}" 274 else 275 "#{request.protocol}assets#{source.length}.example.com" 276 end 277 } 278 ActionController::Base.perform_caching = true 279 280 assert_equal '/javascripts/vanilla.js'.length, 23 281 assert_dom_equal( 282 %(<script src="http://assets23.example.com/javascripts/vanilla.js" type="text/javascript"></script>), 283 javascript_include_tag(:all, :cache => 'vanilla') 284 ) 285 286 assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'vanilla.js')) 287 288 class << @controller.request 289 def protocol() 'https://' end 290 def ssl?() true end 291 end 292 293 assert_equal '/javascripts/secure.js'.length, 22 294 assert_dom_equal( 295 %(<script src="https://localhost/javascripts/secure.js" type="text/javascript"></script>), 296 javascript_include_tag(:all, :cache => 'secure') 297 ) 298 299 assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'secure.js')) 300 301 ensure 302 FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'vanilla.js')) 303 FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'secure.js')) 304 end 305 267 306 def test_caching_javascript_include_tag_when_caching_on_and_using_subdirectory 268 307 ENV["RAILS_ASSET_ID"] = "" 269 308 ActionController::Base.asset_host = 'http://a%d.example.com' -
actionpack/lib/action_controller/cgi_process.rb
old new 3 3 4 4 module ActionController #:nodoc: 5 5 class Base 6 # Process a request extracted from a nCGI object and return a response. Pass false as <tt>session_options</tt> to disable6 # Process a request extracted from a CGI object and return a response. Pass false as <tt>session_options</tt> to disable 7 7 # sessions (large performance increase if sessions are not needed). The <tt>session_options</tt> are the same as for CGI::Session: 8 8 # 9 9 # * <tt>:database_manager</tt> - standard options are CGI::Session::FileStore, CGI::Session::MemoryStore, and CGI::Session::PStore … … 17 17 # an ArgumentError is raised. 18 18 # * <tt>:session_expires</tt> - the time the current session expires, as a +Time+ object. If not set, the session will continue 19 19 # indefinitely. 20 # * <tt>:session_domain</tt> - the hostname domain for which this session is valid. If not set, defaults to the hostname of the20 # * <tt>:session_domain</tt> - the hostname domain for which this session is valid. If not set, defaults to the hostname of the 21 21 # server. 22 22 # * <tt>:session_secure</tt> - if +true+, this session will only work over HTTPS. 23 23 # * <tt>:session_path</tt> - the path for which this session applies. Defaults to the directory of the CGI script. … … 34 34 35 35 class CgiRequest < AbstractRequest #:nodoc: 36 36 attr_accessor :cgi, :session_options 37 class SessionFixationAttempt < StandardError; end #:nodoc: 37 class SessionFixationAttempt < StandardError #:nodoc: 38 end 38 39 39 40 DEFAULT_SESSION_OPTIONS = { 40 41 :database_manager => CGI::Session::CookieStore, # store data in cookie -
actionpack/lib/action_view/helpers/asset_tag_helper.rb
old new 50 50 # stylesheet_include_tag("application") 51 51 # => <link href="http://assets1.example.com/stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" /> 52 52 # 53 # The proc takes a single <tt>source</tt> parameter which is the path of the source asset. This can be used to 54 # generate a particular asset host depending on the asset path. 53 # The proc takes a <tt>source</tt> parameter (which is the path of the source asset) and an optional 54 # <tt>request</tt> parameter (which is an entire instance of an <tt>ActionController::AbstractRequest</tt> 55 # subclass). This can be used to generate a particular asset host depending on the asset path and the particular 56 # request. 55 57 # 56 58 # ActionController::Base.asset_host = Proc.new { |source| 57 59 # if source.starts_with?('/images') … … 65 67 # stylesheet_include_tag("application") 66 68 # => <link href="http://assets.example.com/stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" /> 67 69 # 70 # The optional <tt>request</tt> parameter to the proc is useful in particular for serving assets from an 71 # SSL-protected page. The example proc below disables asset hosting for HTTPS connections, while still sending 72 # assets for plain HTTP requests from asset hosts. This is useful for avoiding mixed media warnings when serving 73 # non-HTTP assets from HTTPS web pages when you don't have an SSL certificate for each of the asset hosts. 74 # 75 # ActionController::Base.asset_host = Proc.new { |source, request| 76 # if request.ssl? 77 # "#{request.protocol}#{request.host_with_port}" 78 # else 79 # "#{request.protocol}assets.example.com" 80 # end 81 # } 82 # 68 83 # === Using asset timestamps 69 84 # 70 85 # By default, Rails will append all asset paths with that asset's timestamp. This allows you to set a cache-expiration date for the … … 461 476 def compute_asset_host(source) 462 477 if host = ActionController::Base.asset_host 463 478 if host.is_a?(Proc) 464 host.call(source) 479 case host.arity 480 when 2: 481 host.call(source, @controller.request) 482 else 483 host.call(source) 484 end 465 485 else 466 486 host % (source.hash % 4) 467 487 end -
actionpack/lib/action_view/template_handlers/erb.rb
old new 4 4 module Util 5 5 HTML_ESCAPE = { '&' => '&', '"' => '"', '>' => '>', '<' => '<' } 6 6 7 # A utility method for escaping HTML tag characters. 8 # This method is also aliased as <tt>h</tt>. 9 # 10 # In your ERb templates, use this method to escape any unsafe content. For example: 11 # <%=h @person.name %> 12 # 13 # ==== Example: 14 # puts html_escape("is a > 0 & a < 10?") 15 # # => is a > 0 & a < 10? 7 16 def html_escape(s) 8 17 s.to_s.gsub(/[&"><]/) { |special| HTML_ESCAPE[special] } 9 18 end