X-Git-Url: http://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Flibs%2Ffilebackend%2FHTTPFileStreamer.php;h=e77d4d421d843fc7fde993c92d34db7db6be125e;hp=a7d064b6e304c157b733b6393c801f29ead50288;hb=a818c667e50ec45397766f1f044ecf39e9f7a072;hpb=c584722cc2e3d33edae58d46c2149063b3fc6d72 diff --git a/includes/libs/filebackend/HTTPFileStreamer.php b/includes/libs/filebackend/HTTPFileStreamer.php index a7d064b6e3..e77d4d421d 100644 --- a/includes/libs/filebackend/HTTPFileStreamer.php +++ b/includes/libs/filebackend/HTTPFileStreamer.php @@ -39,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: @@ -63,7 +84,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 + * @param int $flags Bitfield of STREAM_* constants * @throws MWException * @return bool Success */ @@ -84,9 +105,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 ) { @@ -179,7 +200,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 ) { @@ -202,7 +223,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 */