From 94f888278b778ab5239954f87b167a72a71f826d Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Thu, 2 Dec 2010 16:54:06 +0000 Subject: [PATCH] Strip If-Modified-Since header to a valid timestamp in ResourceLoader; some clients (notably IE) append things like ;length=123. This is valid according to the HTTP spec but rarely used (and ignored by us). The recent wfTimestamp() rewrite caused a fatal error in wfTimestamp() when such a timestamp was fed to it. r77401 fixed this by trimming the timestamp in wfTimestamp() itself, but for cleanliness we should do this in RL too. --- includes/resourceloader/ResourceLoader.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/includes/resourceloader/ResourceLoader.php b/includes/resourceloader/ResourceLoader.php index e5f7a77664..ea7ba55f02 100644 --- a/includes/resourceloader/ResourceLoader.php +++ b/includes/resourceloader/ResourceLoader.php @@ -347,12 +347,17 @@ class ResourceLoader { } // If there's an If-Modified-Since header, respond with a 304 appropriately + // Some clients send "timestamp;length=123". Strip the part after the first ';' + // so we get a valid timestamp. $ims = $context->getRequest()->getHeader( 'If-Modified-Since' ); - if ( $ims !== false && $mtime <= wfTimestamp( TS_UNIX, $ims ) ) { - header( 'HTTP/1.0 304 Not Modified' ); - header( 'Status: 304 Not Modified' ); - wfProfileOut( __METHOD__ ); - return; + if ( $ims !== false ) { + $imsTS = strtok( $ims, ';' ); + if ( $mtime <= wfTimestamp( TS_UNIX, $imsTS ) ) { + header( 'HTTP/1.0 304 Not Modified' ); + header( 'Status: 304 Not Modified' ); + wfProfileOut( __METHOD__ ); + return; + } } // Generate a response -- 2.20.1