core/includes/bootstrap.inc | 2 +- .../system/Tests/Bootstrap/PageCacheTest.php | 25 +++++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index a824957..e5f980e 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -816,7 +816,7 @@ function drupal_send_headers($default_headers = array(), $only_default = FALSE) * fresh page on every request. This prevents authenticated users from seeing * locally cached pages. * - * Also give each page a unique ETag. This will force clients to include both + * Also give each page a unique ETag. This should force clients to include both * an If-Modified-Since header and an If-None-Match header when doing * conditional requests for the page (required by RFC 2616, section 13.3.4), * making the validation more robust. This is a workaround for a bug in Mozilla diff --git a/core/modules/system/lib/Drupal/system/Tests/Bootstrap/PageCacheTest.php b/core/modules/system/lib/Drupal/system/Tests/Bootstrap/PageCacheTest.php index fdf16b9..150e1db 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Bootstrap/PageCacheTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Bootstrap/PageCacheTest.php @@ -128,21 +128,40 @@ function testConditionalRequests() { $this->drupalGet('', array(), array('If-Modified-Since: ' . $last_modified, 'If-None-Match: ' . $etag)); $this->assertResponse(304, 'Conditional request returned 304 Not Modified.'); + $this->assertTrue(strlen($this->drupalGetContent()) == 0, 'No HTML returned.'); $this->drupalGet('', array(), array('If-Modified-Since: ' . gmdate(DATE_RFC822, strtotime($last_modified)), 'If-None-Match: ' . $etag)); $this->assertResponse(304, 'Conditional request with obsolete If-Modified-Since date returned 304 Not Modified.'); + $this->assertTrue(strlen($this->drupalGetContent()) == 0, 'No HTML returned.'); $this->drupalGet('', array(), array('If-Modified-Since: ' . gmdate(DATE_RFC850, strtotime($last_modified)), 'If-None-Match: ' . $etag)); $this->assertResponse(304, 'Conditional request with obsolete If-Modified-Since date returned 304 Not Modified.'); + $this->assertTrue(strlen($this->drupalGetContent()) == 0, 'No HTML returned.'); $this->drupalGet('', array(), array('If-Modified-Since: ' . $last_modified)); + $this->assertResponse(304, 'Conditional request with If-Modified-Since but without If-None-Match returned 304 Not Modified.'); + $this->assertTrue(strlen($this->drupalGetContent()) == 0, 'No HTML returned.'); + + $this->drupalGet('', array(), array('If-None-Match: ' . $etag)); + $this->assertResponse(304, 'Conditional request with If-None-Match but without If-Modified-Since returned 304 Not Modified.'); + $this->assertTrue(strlen($this->drupalGetContent()) == 0, 'No HTML returned.'); + + $this->drupalGet('', array(), array('If-Modified-Since: ' . gmdate(DATE_RFC1123, strtotime($last_modified) + 1), 'If-None-Match: ' . $etag)); + $this->assertResponse(200, 'Conditional request with an If-Modified-Since date newer than Last-Modified returned 200 OK.'); // Verify the page is not printed twice when the cache is warm. $this->assertNoPattern('#assertResponse(200, 'Conditional request without If-None-Match returned 200 OK.'); $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', 'Page was cached.'); - $this->drupalGet('', array(), array('If-Modified-Since: ' . gmdate(DATE_RFC1123, strtotime($last_modified) + 1), 'If-None-Match: ' . $etag)); - $this->assertResponse(200, 'Conditional request with new a If-Modified-Since date newer than Last-Modified returned 200 OK.'); + $this->drupalGet('', array(), array('If-Modified-Since: ' . $last_modified, 'If-None-Match: ' . $etag . '-is-invalid')); + $this->assertResponse(200, 'Conditional request with an invalid If-None-Match ETag value returned 200 OK.'); + // Verify the page is not printed twice when the cache is warm. + $this->assertNoPattern('#assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', 'Page was cached.'); + + $this->drupalGet('', array(), array('If-Modified-Since: ' . gmdate(DATE_RFC1123, strtotime($last_modified) + 1), 'If-None-Match: ' . $etag . '-is-invalid')); + $this->assertResponse(200, 'Conditional request with an If-Modified-Since date nwer than Last-Modified and an invalid If-None-Match ETag value returned 200 OK.'); + // Verify the page is not printed twice when the cache is warm. + $this->assertNoPattern('#assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', 'Page was cached.'); $user = $this->drupalCreateUser();