X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=maintenance%2Fdev%2Fincludes%2Frouter.php;h=bb600bf92fba667990f87a31f7c74eebe304215a;hp=d767df0d8bb56ed0c55dce428b8a9d3fcaef2c1d;hb=424eb75d77f7a7513cd59083198f5b3a407a8715;hpb=243a466018d24415de27815cfae995865c45a66a diff --git a/maintenance/dev/includes/router.php b/maintenance/dev/includes/router.php index d767df0d8b..bb600bf92f 100644 --- a/maintenance/dev/includes/router.php +++ b/maintenance/dev/includes/router.php @@ -74,10 +74,22 @@ if ( $ext == 'php' ) { } else { header( "Content-Type: $mime" ); } - header( "Content-Length: " . filesize( $file ) ); - // Stream that out to the browser - $f = fopen( $file, 'rb' ); - fpassthru( $f ); + + $content = file_get_contents( $file ); + + header( 'Vary: Accept-Encoding' ); + $acceptGzip = preg_match( '/\bgzip\b/', $_SERVER['HTTP_ACCEPT_ENCODING'] ?? '' ); + if ( $acceptGzip && + // Don't compress binary static files (e.g. png) + preg_match( '/text|javascript|json|css|xml|svg/', $mime ) && + // Tiny files tend to grow instead of shrink. – + strlen( $content ) > 150 + ) { + $content = gzencode( $content, 9 ); + header( 'Content-Encoding: gzip' ); + } + header( "Content-Length: " . strlen( $content ) ); + echo $content; return true; }