Add Content-Length header to thumb.php redirects
[lhc/web/wiklou.git] / thumb.php
index c4e690e..03a3f35 100644 (file)
--- a/thumb.php
+++ b/thumb.php
@@ -213,6 +213,7 @@ function wfStreamThumb( array $params ) {
                        if ( count( $varyHeader ) ) {
                                $response->header( 'Vary: ' . implode( ', ', $varyHeader ) );
                        }
+                       $response->header( 'Content-Length: 0' );
                        return;
                }
 
@@ -301,9 +302,15 @@ function wfStreamThumb( array $params ) {
        // Stream the file if it exists already...
        $thumbPath = $img->getThumbPath( $thumbName );
        if ( $img->getRepo()->fileExists( $thumbPath ) ) {
+               $starttime = microtime( true );
                $success = $img->getRepo()->streamFile( $thumbPath, $headers );
+               $streamtime = microtime( true ) - $starttime;
+
                if ( !$success ) {
                        wfThumbError( 500, 'Could not stream the file' );
+               } else {
+                       RequestContext::getMain()->getStats()->timing( 'media.thumbnail.stream', $streamtime );
+                       wfDebugLog( 'thumbnailaccess', time() . ' ' . $thumbPath . ' ' . ob_get_length() . ' Streamed ' );
                }
                return;
        }
@@ -317,8 +324,8 @@ function wfStreamThumb( array $params ) {
                return;
        }
 
-       // Actually generate a new thumbnail
        list( $thumb, $errorMsg ) = wfGenerateThumbnail( $img, $params, $thumbName, $thumbPath );
+
        /** @var MediaTransformOutput|bool $thumb */
 
        // Check for thumbnail generation errors...
@@ -570,7 +577,7 @@ function wfThumbError( $status, $msg ) {
        } else {
                $debug = '';
        }
-       echo <<<EOT
+       $content = <<<EOT
 <!DOCTYPE html>
 <html><head>
 <meta charset="UTF-8" />
@@ -586,4 +593,6 @@ $debug
 </html>
 
 EOT;
+       header( 'Content-Length: ' . strlen( $content ) );
+       echo $content;
 }