X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2Flibs%2Ffilebackend%2FHTTPFileStreamer.php;h=7a11aebf7ebfd4783683a719e6a10136c599e387;hb=65648f5523c9d1b772106e16e2adf57870892bc7;hp=46cd6befd94f705101da52eea797e08bcb3d7e3d;hpb=4816ed72995acb2f849db10d7a552acc613044a9;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/libs/filebackend/HTTPFileStreamer.php b/includes/libs/filebackend/HTTPFileStreamer.php index 46cd6befd9..7a11aebf7e 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: @@ -47,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' ]; } /**