WP-Cache fix for Content-Type in feeds

If you run a busy WordPress site, or even if your site just has a lot of processor-intensive plugins, then you probably already run the WP-Cache plugin (plugin directory, original announcment, recent security update info). Even though my site isn’t super busy, my server is a little light in the RAM department, and using WP-Cache helps the box keep up with requests better.

One minor annoyance, however, is that with WP-Cache enabled, my syndication feeds aren’t delivered with the correct Content-Type. They are all cached with a “text/html” type. Again, this is only a minor annoyance, since I haven’t run across a feed reader yet that cares very much about the Content-Type header. But the Feed Validator does. If it sees an Atom feed delivered with content type “text/html” instead of “application/atom+xml”, it gives you a warning. It still checks the validity of the actual feed content, but there’s that big ugly warning at the top.

But not any more. I dug a little bit into the WP Cache plugin to try to figure out what was going on. The plugin does attempt to preserve the correct content type of pages when it caches them, but the output buffering that it uses to capture the content gets in the way. You can’t get to the generated headers until after you flush the buffer. But you don’t want to flush the buffer until you’ve got all of the data to write into the cache meta files. It’s a catch-22. (Actually, it might be okay to flush the buffer at the point where you need the headers, but I’m not sure without further analysis, and I just don’t have the time right now. I’ll leave that as an exercise for someone else. ;) )

So, if you’re a stickler about minor things like the Content-Type of your feeds, and you’re using WP-Cache, feel free to check out my patch: WP-Cache Feed Content Type Patch. Note that the changes to the wp_cache_get_response_headers() function don’t actually work for me. But I left them in the patch in case anybody else wants to examine that section more closely. It might just be something that works in some combinations of Apache/PHP versions and not others.

Update 2007-10-12: This problem was officially fixed in wp-cache version 2.1.2.

Other Posts of Interest

7 Comments

  1. jon
    Posted 6/19/2007 at 2:26 pm | Permalink

    Can you post the whole patched wp-cache-phase2.php file, please?

  2. Posted 6/19/2007 at 2:46 pm | Permalink

    Sure, here you go:

    wp-cache-phase2.phps
    wp-cache-phase2.txt

  3. Posted 6/19/2007 at 4:22 pm | Permalink

    So, using your wp-cache-phase2.php means we’re done? :)

  4. Posted 6/25/2007 at 1:17 pm | Permalink

    Argh! Please don’t use text/xml! If you insist on using registered MIME types, use application/xml, otherwise just use application/rss+xml and be done with it.

  5. Posted 6/25/2007 at 2:39 pm | Permalink

    Argh! Please don’t use text/xml!

    Hrm. I blindly copied the content type out of the WordPress RSS2 feed code. But I’ve corrected my patch to use application/rss+xml.

  6. Bantai
    Posted 10/11/2007 at 7:06 pm | Permalink

    What is the reason for

    stripos($_SERVER["REQUEST_URI"],’wp-cache-fix’) !== false)

    ?

    If the url does not contain the string `wp-cache-fix`, WP-Cache will cache files that should be filtered out according to the rejected strings (default: wp-), which could pose a security thread.

  7. Posted 10/12/2007 at 9:24 am | Permalink

    Bantai:

    I don’t remember why I added that conditional — it was some time ago. It might have been an experimental change that I forgot to remove before I made the diff.

    But in any case, the problem is fixed in wp-cache version 2.1.2.

5 Trackbacks

  1. By Parche para WP-Cache | La brujula verde on 6/20/2007 at 7:40 am

    [...] Dougal Campbell acaba de publicar un parche para el plugin de WordPress WP-Cache. [...]

  2. [...] Campbell, recently posted a patch for WP-Cache that fixes “one minor annoyance” where sites, with WP-Cache enabled, have [...]

  3. By Around the web | alexking.org on 6/24/2007 at 6:26 pm

    [...] WP-Cache fix for Content-Type in feeds - good stuff. [...]

  4. By Brian Kerr | links for 2007-06-26 on 6/26/2007 at 12:22 am

    [...] geek ramblings | WP-Cache fix for Content-Type in feeds (tags: wordpress cache feeds content-type) [...]

  5. [...] writing). While perusing the comments (I always read the comments about plugins!) I noticed that Dougal had made a tweak to fix a content-type [...]

Post a Comment

Your email is never published nor shared. Comments or website URLs deemed to be off-topic or inappropriate may be deleted at the site owner's discretion.