// 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:
*/
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' ];
}
/**
* @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(