+ /**
+ * 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 ];
+ }
+