X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2Flibs%2Ffilebackend%2FHTTPFileStreamer.php;h=9f8959cba0b4e4398b6aaed10f87bf822c1ca028;hb=65648f5523c9d1b772106e16e2adf57870892bc7;hp=800fdfad3ee121a1ab344381fc0bc8311f32106a;hpb=9c44be0eea12d6b89079bf43c27e7feeadf64ebe;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/libs/filebackend/HTTPFileStreamer.php b/includes/libs/filebackend/HTTPFileStreamer.php index 800fdfad3e..7a11aebf7e 100644 --- a/includes/libs/filebackend/HTTPFileStreamer.php +++ b/includes/libs/filebackend/HTTPFileStreamer.php @@ -19,6 +19,7 @@ * * @file */ +use Wikimedia\Timestamp\ConvertibleTimestamp; /** * Functions related to the output of file content @@ -38,6 +39,27 @@ class HTTPFileStreamer { // Do not try to tear down any PHP output buffers const STREAM_ALLOW_OB = 2; + /** + * Takes HTTP headers in a name => value format and converts them to the weird format + * expected by stream(). + * @param string[] $headers + * @return array[] [ $headers, $optHeaders ] + * @since 1.34 + */ + public static function preprocessHeaders( $headers ) { + $rawHeaders = []; + $optHeaders = []; + foreach ( $headers as $name => $header ) { + $nameLower = strtolower( $name ); + if ( in_array( $nameLower, [ 'range', 'if-modified-since' ], true ) ) { + $optHeaders[$nameLower] = $header; + } else { + $rawHeaders[] = "$name: $header"; + } + } + return [ $rawHeaders, $optHeaders ]; + } + /** * @param string $path Local filesystem path to a file * @param array $params Options map, which includes: @@ -46,12 +68,8 @@ class HTTPFileStreamer { */ public function __construct( $path, array $params = [] ) { $this->path = $path; - $this->obResetFunc = isset( $params['obResetFunc'] ) - ? $params['obResetFunc'] - : [ __CLASS__, 'resetOutputBuffers' ]; - $this->streamMimeFunc = isset( $params['streamMimeFunc'] ) - ? $params['streamMimeFunc'] - : [ __CLASS__, 'contentTypeFromPath' ]; + $this->obResetFunc = $params['obResetFunc'] ?? [ __CLASS__, 'resetOutputBuffers' ]; + $this->streamMimeFunc = $params['streamMimeFunc'] ?? [ __CLASS__, 'contentTypeFromPath' ]; } /** @@ -62,8 +80,7 @@ class HTTPFileStreamer { * @param array $headers Any additional headers to send if the file exists * @param bool $sendErrors Send error messages if errors occur (like 404) * @param array $optHeaders HTTP request header map (e.g. "range") (use lowercase keys) - * @param integer $flags Bitfield of STREAM_* constants - * @throws MWException + * @param int $flags Bitfield of STREAM_* constants * @return bool Success */ public function stream( @@ -83,9 +100,9 @@ class HTTPFileStreamer { is_int( $header ) ? HttpStatus::header( $header ) : header( $header ); }; - MediaWiki\suppressWarnings(); + Wikimedia\suppressWarnings(); $info = stat( $this->path ); - MediaWiki\restoreWarnings(); + Wikimedia\restoreWarnings(); if ( !is_array( $info ) ) { if ( $sendErrors ) { @@ -178,7 +195,7 @@ class HTTPFileStreamer { * Send out a standard 404 message for a file * * @param string $fname Full name and path of the file to stream - * @param integer $flags Bitfield of STREAM_* constants + * @param int $flags Bitfield of STREAM_* constants * @since 1.24 */ public static function send404Message( $fname, $flags = 0 ) { @@ -201,7 +218,7 @@ class HTTPFileStreamer { * Convert a Range header value to an absolute (start, end) range tuple * * @param string $range Range header value - * @param integer $size File size + * @param int $size File size * @return array|string Returns error string on failure (start, end, length) * @since 1.24 */