From f1d13a6653c67e59120d424fd0742f6514adb01c Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Wed, 12 Sep 2012 10:35:47 -0700 Subject: [PATCH] Add Vary: X-Forwarded-Proto to the thumb.php redirect Also added missing return. Untested. Change-Id: I975b82d18ba98d1d9b1f2124150af9e5c41f418e --- thumb.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/thumb.php b/thumb.php index 9a2d00b86c..2edc28027a 100644 --- a/thumb.php +++ b/thumb.php @@ -96,6 +96,7 @@ function wfThumbHandle404() { * @return void */ function wfStreamThumb( array $params ) { + global $wgVaryOnXFP; wfProfileIn( __METHOD__ ); $headers = array(); // HTTP headers to send @@ -159,6 +160,7 @@ function wfStreamThumb( array $params ) { } // Check permissions if there are read restrictions + $varyHeader = array(); if ( !in_array( 'read', User::getGroupPermissions( array( '*' ) ), true ) ) { if ( !$img->getTitle() || !$img->getTitle()->userCan( 'read' ) ) { wfThumbError( 403, 'Access denied. You do not have permission to access ' . @@ -167,7 +169,7 @@ function wfStreamThumb( array $params ) { return; } $headers[] = 'Cache-Control: private'; - $headers[] = 'Vary: Cookie'; + $varyHeader[] = 'Cookie'; } // Check the source file storage path @@ -232,6 +234,12 @@ function wfStreamThumb( array $params ) { $response->header( 'Location: ' . wfExpandUrl( $img->getThumbUrl( $thumbName ), PROTO_CURRENT ) ); $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + 7*86400 ) . ' GMT' ); + if ( $wgVaryOnXFP ) { + $varyHeader[] = 'X-Forwarded-Proto'; + } + $response->header( 'Vary: ' . implode( ', ', $varyHeader ) ); + wfProfileOut( __METHOD__ ); + return; } else { wfThumbError( 404, 'The source file for the specified thumbnail does not exist.' ); wfProfileOut( __METHOD__ ); @@ -240,6 +248,7 @@ function wfStreamThumb( array $params ) { } $thumbPath = $img->getThumbPath( $thumbName ); if ( $img->getRepo()->fileExists( $thumbPath ) ) { + $headers[] = 'Vary: ' . implode( ', ', $varyHeader ); $img->getRepo()->streamFile( $thumbPath, $headers ); wfProfileOut( __METHOD__ ); return; @@ -249,6 +258,7 @@ function wfStreamThumb( array $params ) { wfProfileOut( __METHOD__ ); return; } + $headers[] = 'Vary: ' . implode( ', ', $varyHeader ); // Thumbnail isn't already there, so create the new thumbnail... try { -- 2.20.1