Fixing Batcache to Send The Correct Content-Type Header

I’m a fan of Batcache, the Memcached-based WordPress full-page cache solution, but I’ve discovered that it ignores the content-type header set when the page is initially generated and re-sends all content with content-type: text/html. I posted a note about this at the WordPress support forums, but then I realized what the problem was: apache_response_headers() doesn’t return the content type, but headers_list() does.

The solution is to replace apache_response_headers() with headers_list() in the code, though headers_list() is PHP 5+ only, so it might be a while before we see a change like this committed. Still, I’ll shamelessly tag Andy Skelton (Batcache’s author) on it.

5 thoughts on “Fixing Batcache to Send The Correct Content-Type Header

  1. It’s a shame we can’t rely on PHP knowing the headers sent. That’s why I added the status_header filter. Unfortunately WordPress doesn’t have a similar function for all headers. If you want to patch with a function_exists check, I’ll commit it.

  2. Pingback: Memcached and WordPress MU — Chris Heisel

  3. Thanks for the post. I was having problems on our sites with pdf’s coming through for non-logged in users as gibberish (trying to output a pdf file as text/html). Dropped in your fix. and things seem to be all working once again…

    Good find 😉

  4. Hi Casey
    Has this issue been fixed and I am missing? I used the advanced-cache.php and batcahe.php from get hub and still get content-type issues.

Comments are closed.