Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

action caching sets wrong content-type when :cache_path is a string

#1585

If someone uses a string for :cache_path


caches_action :show, :cache_path => 'http://test.host/custom/show'

action caching will be broken for content types other than "text/html".

Patch: http://gist.github.com/37050

Similar bug seems to affect page caching: #1244 caches_page does not respect Accept header

Reported by Mislav · December 17th, 2008 @ 01:32 PM

State: resolved
Milestone: none
Assigned to: Michael Koziarski Michael Koziarski
Importance: none

Activity

  1. Michael Koziarski
    Michael Koziarski
    • Milestone cleared.
    • Assigned user set to Michael Koziarski

    December 17th, 2008 @ 01:46 PM

  2. Christoph Petschnig
    Christoph Petschnig

    This bug occurs also with a Proc object that returns a string.

    The gist-url with the patch was deleted, so I post an easy workaround for this bug. Simply set the content type yourself somewhere inside the macro, like:

    caches_action :index, :if => Proc.new { |c| result = c.cache_me?; c.headers["Content-Type"] = 'text/xml; charset=UTF-8' if result; result },

    :cache_path => Proc.new { |c| File.join('abc', c.some_method) }
    
    

    February 26th, 2009 @ 11:00 AM

  3. Mislav
    Mislav

    Aw damn, I've been cleaning up my gists and deleted the patch because I thought it was applied. If anyone needs it back, shout now. I was pretty sure this was fixed soon after this was reported.

    Christoph, can you make a failing test for your case?

    February 26th, 2009 @ 01:04 PM

  4. Christoph Petschnig
    Christoph Petschnig

    Ok, I made the failing tests.

    I choose to attach a whole rails project instead of a single file. Please look at docs/README for some explanation.

    I am not an experienced tests writer, yet it seems to me, that I found two other bugs while writing the tests. Please look at the comments in test/functional/xml_caching_controller_test.rb therefore.

    I would like to investigate that a little further, but I will be buzy for the next seven days.

    February 28th, 2009 @ 12:25 AM

  5. Mislav
    Mislav
    • Tag changed from caches_action, format, patch to bug, caches_action, caching, format, patch

    Here's the revised patch with failing tests for both cases: string key or proc that returns a string.

    March 10th, 2009 @ 11:05 PM

  6. Repository
    Repository
    • State changed from new to resolved

    (from [fa45540cdb30cee44983c9121e3ebfc317d21668]) Ensure correct content type is declared after cache hits on actions with string cache keys [#1585 action caching sets wrong content-type when :cache_path is a string state:resolved]

    Signed-off-by: Pratik Naik pratiknaik@gmail.com http://github.com/rails/rails/co...

    March 11th, 2009 @ 12:07 AM