|
|
|
@ -82,6 +82,30 @@ final class StreamContextFactory
|
|
|
|
|
|
|
|
|
|
$options = array_replace_recursive($options, $defaultOptions);
|
|
|
|
|
|
|
|
|
|
if (isset($options['http']['header'])) {
|
|
|
|
|
$options['http']['header'] = self::fixHttpHeaderField($options['http']['header']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return stream_context_create($options, $defaultParams);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A bug in PHP prevents the headers from correctly beeing sent when a content-type header is present and
|
|
|
|
|
* NOT at the end of the array
|
|
|
|
|
*
|
|
|
|
|
* This method fixes the array by moving the content-type header to the end
|
|
|
|
|
*
|
|
|
|
|
* @link https://bugs.php.net/bug.php?id=61548
|
|
|
|
|
* @param $header
|
|
|
|
|
* @return array
|
|
|
|
|
* @author Markus Tacker <m@coderbyheart.de>
|
|
|
|
|
*/
|
|
|
|
|
public static function fixHttpHeaderField($header)
|
|
|
|
|
{
|
|
|
|
|
if (!is_array($header)) $header = explode("\r\n", $header);
|
|
|
|
|
uasort($header, function ($el) {
|
|
|
|
|
return preg_match('/^content-type/i', $el) ? 1 : -1;
|
|
|
|
|
});
|
|
|
|
|
return $header;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|