404 Caching returns HTTP 200 status code for 404 pages #197

Closed
raamdev opened this Issue Jun 5, 2014 · 4 comments

Comments

Projects
None yet
2 participants
Owner

raamdev commented Jun 5, 2014

When the 404 Caching option is enabled, Quick Cache caches the 404 page and serves the cached file upon all subsequent 404 errors. However, it also returns a 200 OK HTTP status code, instead of the proper 404 Not Found.

Here's how you can reproduce this:

  1. Enable 404 Caching
  2. Visit a non-existent page to create a 404 cache file
  3. Run wget --server-response <non-existent page URL> and observe the output
  4. Disable Quick Cache 404 Caching
  5. Run wget --server-response <non-existent page URL> and observe the output

Note that with Quick Cache 404 Caching disabled, WordPress returns the correct HTTP status code.

# ----------- Quick Cache 404 Caching Enabled

$ wget -v http://qcpro.dev/asdasd
--2014-06-05 14:59:23--  http://qcpro.dev/asdasd
Resolving qcpro.dev (qcpro.dev)... 127.0.0.1
Connecting to qcpro.dev (qcpro.dev)|127.0.0.1|:80... connected.
HTTP request sent, awaiting response... 200 OK

# ----------- Quick Cache 404 Caching Disabled

$ wget -v http://qcpro.dev/asdasd
--2014-06-05 15:00:50--  http://qcpro.dev/asdasd
Resolving qcpro.dev (qcpro.dev)... 127.0.0.1
Connecting to qcpro.dev (qcpro.dev)|127.0.0.1|:80... connected.
HTTP request sent, awaiting response... 404 Not Found
2014-06-05 15:00:51 ERROR 404: Not Found.

See http://wordpress.org/support/topic/cached-404-returns-200

raamdev added this to the Next Release milestone Jun 5, 2014

Owner

jaswrks commented Jun 17, 2014

Ah.. I see. Darn, this actually comes back to the issue with PHP itself, where headers_list() is currently missing the HTTP status code header. Quick Cache would pick this up properly if that were not broken.

From this line in the dev branch.

file_put_contents($cache_file_tmp, serialize(headers_list()).'<!--headers-->'.$cache)

What we could do is stuff the 404 header into the cache file like we already do for the other headers preserved by this line inside the advanced-cache.tpl.php file. In a case where there is a 404 detected, the 404 cache file can include the 404 response header and Quick Cache will repeat this automatically on each subsequent cache hit to that 404; whether it be through a symlink or not.

Owner

jaswrks commented Jun 17, 2014

@raamdev I will have to work with this portion of the code when I work on websharks#56, would you like me to fix this also at the same time?

jaswrks was assigned by raamdev Jun 17, 2014

Owner

raamdev commented Jun 17, 2014

@jaswsinc Yes, if you could fix this along with #56, that would be great! I've assigned this to you. Thanks!

@jaswrks jaswrks pushed a commit that referenced this issue Jun 18, 2014

JasWSInc 404 status header fix; see websharks/comet-cache#197 60fa420

@jaswrks jaswrks pushed a commit to websharks/comet-cache-pro that referenced this issue Jun 18, 2014

JasWSInc 404 status header fix; see websharks/comet-cache#197 27e3193

@jaswrks jaswrks pushed a commit that referenced this issue Jun 18, 2014

JasWSInc Improve comments; see websharks/comet-cache#197 466fe4a

@jaswrks jaswrks pushed a commit to websharks/comet-cache-pro that referenced this issue Jun 18, 2014

JasWSInc Improve comments; see websharks/comet-cache#197 bb3f9ee

This was referenced Jun 18, 2014

Owner

raamdev commented Jun 18, 2014

Closed by #219.

raamdev closed this Jun 18, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment