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

Changeset 6970

Show
Ignore:
Timestamp:
06/08/07 05:01:35 (1 year ago)
Author:
bitsweat
Message:

Action caching is limited to GET requests returning 200 OK status. Closes #3335.

Files:

Legend:

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

    r6968 r6970  
    11*SVN* 
     2 
     3* Action caching is limited to GET requests returning 200 OK status.  #3335 [tom@craz8.com, halfbyte, Dan Kubb, Josh Peek] 
    24 
    35* Improve Text Helper test coverage.  #7274 [Rob Sanheim, Josh Peek] 
  • trunk/actionpack/lib/action_controller/caching.rb

    r6868 r6970  
    241241 
    242242        def after(controller) 
    243           return if !@actions.include?(controller.action_name.intern) || controller.rendered_action_cache 
     243          return if !@actions.include?(controller.action_name.intern) || controller.rendered_action_cache || !caching_allowed(controller) 
    244244          controller.write_fragment(controller.action_cache_path.path, controller.response.body) 
    245245        end 
    246          
     246 
    247247        private 
    248            
    249248          def set_content_type!(controller, extension) 
    250249            controller.response.content_type = Mime::EXTENSION_LOOKUP[extension].to_s if extension 
    251250          end 
    252            
     251 
    253252          def path_options_for(controller, options) 
    254253            ((path_options = options[:cache_path]).respond_to?(:call) ? path_options.call(controller) : path_options) || {} 
    255254          end 
    256            
     255 
     256          def caching_allowed(controller) 
     257            controller.request.get? && controller.response.headers['Status'].to_i == 200 
     258          end 
    257259      end 
    258260       
  • trunk/actionpack/test/controller/caching_test.rb

    r6868 r6970  
    122122 
    123123class ActionCachingTestController < ActionController::Base 
    124   caches_action :index 
     124  caches_action :index, :redirected, :forbidden 
    125125  caches_action :show, :cache_path => 'http://test.host/custom/show' 
    126126  caches_action :edit, :cache_path => Proc.new { |c| c.params[:id] ? "http://test.host/#{c.params[:id]};edit" : "http://test.host/edit" } 
     
    130130    render :text => @cache_this 
    131131  end 
    132    
     132 
     133  def redirected 
     134    redirect_to :action => 'index' 
     135  end 
     136 
     137  def forbidden 
     138    render :text => "Forbidden" 
     139    headers["Status"] = "403 Forbidden" 
     140  end 
     141 
    133142  alias_method :show, :index 
    134143  alias_method :edit, :index 
     
    246255  end 
    247256 
     257  def test_redirect_is_not_cached 
     258    get :redirected 
     259    assert_response :redirect 
     260    reset! 
     261 
     262    get :redirected 
     263    assert_response :redirect 
     264  end 
     265 
     266  def test_forbidden_is_not_cached 
     267    get :forbidden 
     268    assert_response :forbidden 
     269    reset! 
     270 
     271    get :forbidden 
     272    assert_response :forbidden 
     273  end 
     274 
    248275  def test_xml_version_of_resource_is_treated_as_different_cache 
    249276    @mock_controller.mock_url_for = 'http://example.org/posts/'