Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

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

raamdev opened this issue Jun 5, 2014 · 4 comments
Assignees
Milestone

Comments

@raamdev
Copy link
Contributor

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 raamdev added this to the Next Release milestone Jun 5, 2014
@jaswrks
Copy link

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.

@jaswrks
Copy link

jaswrks commented Jun 17, 2014

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

@raamdev
Copy link
Contributor Author

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 pushed a commit that referenced this issue Jun 18, 2014
jaswrks pushed a commit to wpsharks/comet-cache-pro that referenced this issue Jun 18, 2014
jaswrks pushed a commit that referenced this issue Jun 18, 2014
jaswrks pushed a commit to wpsharks/comet-cache-pro that referenced this issue Jun 18, 2014
This was referenced Jun 18, 2014
@raamdev
Copy link
Contributor Author

raamdev commented Jun 18, 2014

Closed by #219.

@raamdev raamdev closed this as completed Jun 18, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants