When Drupal serves an error page from cache, it returns 304 as status code if headers if-modified-since and if-none-match match expected values, as defined in includes/bootstrap.inc

function drupal_serve_page_from_cache(stdClass $cache) {
  // ...

  // See if the client has provided the required HTTP headers.
  $if_modified_since = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) : FALSE;
  $if_none_match = isset($_SERVER['HTTP_IF_NONE_MATCH']) ? stripslashes($_SERVER['HTTP_IF_NONE_MATCH']) : FALSE;

  if ($if_modified_since && $if_none_match
      && $if_none_match == $etag // etag must match
      && $if_modified_since == $cache->created) {  // if-modified-since must match
    header($_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified');
    drupal_send_headers($default_headers);
    return;
  }

  // ...

From W3 specifications about If-None-Match header:

If the request would, without the If-None-Match header field, result in anything other than a 2xx or 304 status, then the If-None-Match header MUST be ignored.

So cached status code must be checked, and this block must be skipped for 4xx status codes.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Cinedin created an issue. See original summary.

Cinedin’s picture

Status: Active » Needs review
FileSize
1.94 KB
Cinedin’s picture

FileSize
2.04 KB
Cinedin’s picture

Project: » Drupal core
Version: » 7.39
Component: Code » cache system
cilefen’s picture

Priority: Major » Normal
Issue tags: -error, -status code, -cache

I moved this to Normal priority for now and removed tags that do not clarify the issue.

Please check if this is an issue with Drupal 8. If so, it must be fixed there first according to the backport policy. If it is, move it to branch 8.0.x-dev and tag it “Needs backport to D7”.

Version: 7.39 » 7.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.