From a4379d8f9e06bbf28d43525978043cb447566fee Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Thu, 18 Jul 2013 10:52:23 -0700 Subject: [PATCH] resourceloader: Always send headers with a 304 response There was a code path that sent plain 304s without Expires or any other headers. Fix this by moving the call to sendResponseHeaders() into tryLastModified(). Bug: 51283 Change-Id: I15d13c5d32102f53bf3e3aaac01d76967e968f78 --- RELEASE-NOTES-1.26 | 1 + includes/resourceloader/ResourceLoader.php | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/RELEASE-NOTES-1.26 b/RELEASE-NOTES-1.26 index 57166efb71..0b3f29c658 100644 --- a/RELEASE-NOTES-1.26 +++ b/RELEASE-NOTES-1.26 @@ -17,6 +17,7 @@ production. ==== External libraries ==== === Bug fixes in 1.26 === +* (bug 51283) load.php sometimes sends 304 response without full headers === Action API changes in 1.26 === * API action=query&list=tags: The displayname can now be boolean false if the diff --git a/includes/resourceloader/ResourceLoader.php b/includes/resourceloader/ResourceLoader.php index f8d8d2f54b..7da3aec8e7 100644 --- a/includes/resourceloader/ResourceLoader.php +++ b/includes/resourceloader/ResourceLoader.php @@ -764,6 +764,9 @@ class ResourceLoader { header( 'HTTP/1.0 304 Not Modified' ); header( 'Status: 304 Not Modified' ); + + // Send content type and cache headers + $this->sendResponseHeaders( $context, $mtime, false ); return true; } } @@ -798,18 +801,18 @@ class ResourceLoader { } if ( $good ) { $ts = $fileCache->cacheTimestamp(); - // Send content type and cache headers - $this->sendResponseHeaders( $context, $ts, false ); // If there's an If-Modified-Since header, respond with a 304 appropriately if ( $this->tryRespondLastModified( $context, $ts ) ) { return false; // output handled (buffers cleared) } - $response = $fileCache->fetchText(); // Capture any PHP warnings from the output buffer and append them to the // response in a comment if we're in debug mode. if ( $context->getDebug() && strlen( $warnings = ob_get_contents() ) ) { $response = "/*\n$warnings\n*/\n" . $response; } + // Send content type and cache headers + $this->sendResponseHeaders( $context, $ts, false ); + $response = $fileCache->fetchText(); // Remove the output buffer and output the response ob_end_clean(); echo $response . "\n/* Cached {$ts} */"; -- 2.20.1