Merge "Title: Title::getSubpage should not lose the interwiki prefix"
[lhc/web/wiklou.git] / includes / libs / filebackend / HTTPFileStreamer.php
index 9f8959c..7a11aeb 100644 (file)
@@ -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' ];
        }
 
        /**
@@ -64,7 +81,6 @@ class HTTPFileStreamer {
         * @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 int $flags Bitfield of STREAM_* constants
-        * @throws MWException
         * @return bool Success
         */
        public function stream(