This commit is contained in:
Javier Casares 2026-06-02 18:49:45 +00:00
commit 1dd5809016
26 changed files with 21760 additions and 3778 deletions

View file

@ -155,6 +155,24 @@ final class AppendStream implements StreamInterface
*/
public function seek($offset, $whence = SEEK_SET): void
{
if (!\is_int($offset)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to StreamInterface::seek() is deprecated; guzzlehttp/psr7 3.0 requires int for $offset.',
\get_debug_type($offset)
);
}
if (!\is_int($whence)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to StreamInterface::seek() is deprecated; guzzlehttp/psr7 3.0 requires int for $whence.',
\get_debug_type($whence)
);
}
if (!$this->seekable) {
throw new \RuntimeException('This AppendStream is not seekable');
} elseif ($whence !== SEEK_SET) {
@ -187,6 +205,19 @@ final class AppendStream implements StreamInterface
*/
public function read($length): string
{
if (!\is_int($length)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to StreamInterface::read() is deprecated; guzzlehttp/psr7 3.0 requires int for $length.',
\get_debug_type($length)
);
}
if ($this->streams === []) {
return '';
}
$buffer = '';
$total = count($this->streams) - 1;
$remaining = $length;
@ -235,6 +266,15 @@ final class AppendStream implements StreamInterface
public function write($string): int
{
if (!\is_string($string)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to StreamInterface::write() is deprecated; guzzlehttp/psr7 3.0 requires string for $string.',
\get_debug_type($string)
);
}
throw new \RuntimeException('Cannot write to an AppendStream');
}
@ -243,6 +283,15 @@ final class AppendStream implements StreamInterface
*/
public function getMetadata($key = null)
{
if ($key !== null && !\is_string($key)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to StreamInterface::getMetadata() is deprecated; guzzlehttp/psr7 3.0 requires string|null for $key.',
\get_debug_type($key)
);
}
return $key ? null : [];
}
}

View file

@ -86,6 +86,24 @@ final class BufferStream implements StreamInterface
public function seek($offset, $whence = SEEK_SET): void
{
if (!\is_int($offset)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to StreamInterface::seek() is deprecated; guzzlehttp/psr7 3.0 requires int for $offset.',
\get_debug_type($offset)
);
}
if (!\is_int($whence)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to StreamInterface::seek() is deprecated; guzzlehttp/psr7 3.0 requires int for $whence.',
\get_debug_type($whence)
);
}
throw new \RuntimeException('Cannot seek a BufferStream');
}
@ -104,6 +122,15 @@ final class BufferStream implements StreamInterface
*/
public function read($length): string
{
if (!\is_int($length)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to StreamInterface::read() is deprecated; guzzlehttp/psr7 3.0 requires int for $length.',
\get_debug_type($length)
);
}
$currentLength = strlen($this->buffer);
if ($length >= $currentLength) {
@ -124,6 +151,15 @@ final class BufferStream implements StreamInterface
*/
public function write($string): int
{
if (!\is_string($string)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to StreamInterface::write() is deprecated; guzzlehttp/psr7 3.0 requires string for $string.',
\get_debug_type($string)
);
}
$this->buffer .= $string;
if (strlen($this->buffer) >= $this->hwm) {
@ -138,6 +174,15 @@ final class BufferStream implements StreamInterface
*/
public function getMetadata($key = null)
{
if ($key !== null && !\is_string($key)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to StreamInterface::getMetadata() is deprecated; guzzlehttp/psr7 3.0 requires string|null for $key.',
\get_debug_type($key)
);
}
if ($key === 'hwm') {
return $this->hwm;
}

View file

@ -25,6 +25,9 @@ final class CachingStream implements StreamInterface
*/
private $stream;
/** @var bool */
private $detached = false;
/**
* We will treat the buffer object as the body of the stream
*
@ -41,6 +44,10 @@ final class CachingStream implements StreamInterface
public function getSize(): ?int
{
if ($this->detached) {
return null;
}
$remoteSize = $this->remoteStream->getSize();
if (null === $remoteSize) {
@ -57,6 +64,24 @@ final class CachingStream implements StreamInterface
public function seek($offset, $whence = SEEK_SET): void
{
if (!\is_int($offset)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to StreamInterface::seek() is deprecated; guzzlehttp/psr7 3.0 requires int for $offset.',
\get_debug_type($offset)
);
}
if (!\is_int($whence)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to StreamInterface::seek() is deprecated; guzzlehttp/psr7 3.0 requires int for $whence.',
\get_debug_type($whence)
);
}
if ($whence === SEEK_SET) {
$byte = $offset;
} elseif ($whence === SEEK_CUR) {
@ -77,8 +102,16 @@ final class CachingStream implements StreamInterface
// Read the remoteStream until we have read in at least the amount
// of bytes requested, or we reach the end of the file.
while ($diff > 0 && !$this->remoteStream->eof()) {
$this->read($diff);
$diff = $byte - $this->stream->getSize();
$previousSize = $this->stream->getSize();
$previousSkipReadBytes = $this->skipReadBytes;
$data = $this->read($diff);
$currentSize = $this->stream->getSize();
if ($data === '' && $currentSize === $previousSize && $this->skipReadBytes === $previousSkipReadBytes) {
break;
}
$diff = $byte - $currentSize;
}
} else {
// We can just do a normal seek since we've already seen this byte.
@ -88,6 +121,15 @@ final class CachingStream implements StreamInterface
public function read($length): string
{
if (!\is_int($length)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to StreamInterface::read() is deprecated; guzzlehttp/psr7 3.0 requires int for $length.',
\get_debug_type($length)
);
}
// Perform a regular read on any previously read data from the buffer
$data = $this->stream->read($length);
$remaining = $length - strlen($data);
@ -109,7 +151,11 @@ final class CachingStream implements StreamInterface
}
$data .= $remoteData;
$this->stream->write($remoteData);
// A short cache write would silently corrupt later replays, so fail loudly.
if ($this->stream->write($remoteData) !== strlen($remoteData)) {
throw new \RuntimeException('Unable to cache the entire read from the remote stream');
}
}
return $data;
@ -117,6 +163,15 @@ final class CachingStream implements StreamInterface
public function write($string): int
{
if (!\is_string($string)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to StreamInterface::write() is deprecated; guzzlehttp/psr7 3.0 requires string for $string.',
\get_debug_type($string)
);
}
// When appending to the end of the currently read stream, you'll want
// to skip bytes from being read from the remote stream to emulate
// other stream wrappers. Basically replacing bytes of data of a fixed
@ -134,6 +189,23 @@ final class CachingStream implements StreamInterface
return $this->stream->eof() && $this->remoteStream->eof();
}
public function detach()
{
if ($this->detached) {
return null;
}
$position = $this->tell();
$this->cacheEntireStream();
$this->stream->seek($position);
$resource = $this->stream->detach();
$this->detached = true;
return $resource;
}
/**
* Close both the remote stream and buffer stream
*/
@ -141,6 +213,7 @@ final class CachingStream implements StreamInterface
{
$this->remoteStream->close();
$this->stream->close();
$this->detached = true;
}
private function cacheEntireStream(): int

View file

@ -32,6 +32,15 @@ final class DroppingStream implements StreamInterface
public function write($string): int
{
if (!\is_string($string)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to StreamInterface::write() is deprecated; guzzlehttp/psr7 3.0 requires string for $string.',
\get_debug_type($string)
);
}
$diff = $this->maxLength - $this->stream->getSize();
// Begin returning 0 when the underlying stream is too large.

View file

@ -7,7 +7,7 @@ namespace GuzzleHttp\Psr7;
use Psr\Http\Message\StreamInterface;
/**
* Compose stream implementations based on a hash of functions.
* Compose stream implementations based on a hash of callables.
*
* Allows for easy testing and extension of a provided stream without needing
* to create a concrete class for a simple extension point.
@ -31,7 +31,7 @@ final class FnStream implements StreamInterface
{
$this->methods = $methods;
// Create the functions on the class
// Create the callables on the class
foreach ($methods as $name => $fn) {
$this->{'_fn_'.$name} = $fn;
}
@ -73,7 +73,7 @@ final class FnStream implements StreamInterface
* specific method calls.
*
* @param StreamInterface $stream Stream to decorate
* @param array<string, callable> $methods Hash of method name to a closure
* @param array<string, callable> $methods Hash of method name to a callable
*
* @return FnStream
*/
@ -142,6 +142,24 @@ final class FnStream implements StreamInterface
public function seek($offset, $whence = SEEK_SET): void
{
if (!\is_int($offset)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to StreamInterface::seek() is deprecated; guzzlehttp/psr7 3.0 requires int for $offset.',
\get_debug_type($offset)
);
}
if (!\is_int($whence)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to StreamInterface::seek() is deprecated; guzzlehttp/psr7 3.0 requires int for $whence.',
\get_debug_type($whence)
);
}
($this->_fn_seek)($offset, $whence);
}
@ -152,6 +170,15 @@ final class FnStream implements StreamInterface
public function write($string): int
{
if (!\is_string($string)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to StreamInterface::write() is deprecated; guzzlehttp/psr7 3.0 requires string for $string.',
\get_debug_type($string)
);
}
return ($this->_fn_write)($string);
}
@ -162,6 +189,15 @@ final class FnStream implements StreamInterface
public function read($length): string
{
if (!\is_int($length)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to StreamInterface::read() is deprecated; guzzlehttp/psr7 3.0 requires int for $length.',
\get_debug_type($length)
);
}
return ($this->_fn_read)($length);
}
@ -175,6 +211,15 @@ final class FnStream implements StreamInterface
*/
public function getMetadata($key = null)
{
if ($key !== null && !\is_string($key)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to StreamInterface::getMetadata() is deprecated; guzzlehttp/psr7 3.0 requires string|null for $key.',
\get_debug_type($key)
);
}
return ($this->_fn_getMetadata)($key);
}
}

View file

@ -22,7 +22,7 @@ final class Header
foreach ((array) $header as $value) {
foreach (self::splitList($value) as $val) {
$part = [];
foreach (preg_split('/;(?=([^"]*"[^"]*")*[^"]*$)/', $val) ?: [] as $kvp) {
foreach (self::splitParameters($val) as $kvp) {
if (preg_match_all('/<[^>]+>|[^=]+/', $kvp, $matches)) {
$m = $matches[0];
if (isset($m[1])) {
@ -41,6 +41,50 @@ final class Header
return $params;
}
/**
* Split a header value into semicolon-separated parameters.
*
* @return string[]
*/
private static function splitParameters(string $value): array
{
$values = [];
$start = 0;
$isQuoted = false;
$isEscaped = false;
for ($i = 0, $max = \strlen($value); $i < $max; ++$i) {
$char = $value[$i];
if ($isEscaped) {
$isEscaped = false;
continue;
}
if ($isQuoted && $char === '\\') {
$isEscaped = true;
continue;
}
if ($char === '"') {
$isQuoted = !$isQuoted;
continue;
}
if (!$isQuoted && $char === ';') {
$values[] = \substr($value, $start, $i - $start);
$start = $i + 1;
}
}
$values[] = \substr($value, $start);
return $values;
}
/**
* Converts an array of header values that may contain comma separated
* headers into an array of headers with no comma separated values.

View file

@ -61,11 +61,15 @@ final class LimitStream implements StreamInterface
{
if (null === ($length = $this->stream->getSize())) {
return null;
} elseif ($this->limit === -1) {
return $length - $this->offset;
} else {
return min($this->limit, $length - $this->offset);
}
$size = $length - $this->offset;
if ($this->limit !== -1) {
$size = min($this->limit, $size);
}
return max(0, $size);
}
/**
@ -73,6 +77,24 @@ final class LimitStream implements StreamInterface
*/
public function seek($offset, $whence = SEEK_SET): void
{
if (!\is_int($offset)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to StreamInterface::seek() is deprecated; guzzlehttp/psr7 3.0 requires int for $offset.',
\get_debug_type($offset)
);
}
if (!\is_int($whence)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to StreamInterface::seek() is deprecated; guzzlehttp/psr7 3.0 requires int for $whence.',
\get_debug_type($whence)
);
}
if ($whence !== SEEK_SET || $offset < 0) {
throw new \RuntimeException(sprintf(
'Cannot seek to offset %s with whence %s',
@ -139,6 +161,15 @@ final class LimitStream implements StreamInterface
public function read($length): string
{
if (!\is_int($length)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to StreamInterface::read() is deprecated; guzzlehttp/psr7 3.0 requires int for $length.',
\get_debug_type($length)
);
}
if ($this->limit === -1) {
return $this->stream->read($length);
}

View file

@ -69,12 +69,17 @@ final class Message
$body->rewind();
$summary = $body->read($truncateAt);
$body->rewind();
if ($size > $truncateAt) {
if (preg_match('//u', $summary) !== 1) {
$summary = self::trimTrailingIncompleteUtf8Character($summary, $body->read(3));
}
$summary .= ' (truncated...)';
}
$body->rewind();
// Matches any printable character, including unicode characters:
// letters, marks, numbers, punctuation, spacing, and separators.
if (preg_match('/[^\pL\pM\pN\pP\pS\pZ\n\r\t]/u', $summary) !== 0) {
@ -84,6 +89,60 @@ final class Message
return $summary;
}
/**
* Trims a partial UTF-8 character from the end of a truncated string.
*/
private static function trimTrailingIncompleteUtf8Character(string $summary, string $lookahead): string
{
$length = strlen($summary);
if ($length === 0) {
return $summary;
}
$start = $length - 1;
while ($start >= 0) {
$byte = ord($summary[$start]);
if ($byte < 0x80 || $byte > 0xBF) {
break;
}
--$start;
}
if ($start < 0) {
return $summary;
}
$lead = ord($summary[$start]);
if ($lead >= 0xC2 && $lead <= 0xDF) {
$expectedLength = 2;
} elseif ($lead >= 0xE0 && $lead <= 0xEF) {
$expectedLength = 3;
} elseif ($lead >= 0xF0 && $lead <= 0xF4) {
$expectedLength = 4;
} else {
return $summary;
}
$availableLength = $length - $start;
if ($availableLength >= $expectedLength) {
return $summary;
}
$sequence = substr($summary, $start).substr($lookahead, 0, $expectedLength - $availableLength);
if (strlen($sequence) !== $expectedLength || preg_match('//u', $sequence) !== 1) {
return $summary;
}
return substr($summary, 0, $start);
}
/**
* Attempts to rewind a message body and throws an exception on failure.
*
@ -174,6 +233,23 @@ final class Message
* @param array $headers Array of headers (each value an array).
*/
public static function parseRequestUri(string $path, array $headers): string
{
$host = self::getHostFromHeaders($headers);
// If no host is found, then a full URI cannot be constructed.
if ($host === null) {
return $path;
}
$scheme = substr($host, -4) === ':443' ? 'https' : 'http';
return $scheme.'://'.$host.'/'.ltrim($path, '/');
}
/**
* @param array $headers Array of headers (each value an array).
*/
private static function getHostFromHeaders(array $headers): ?string
{
$hostKey = array_filter(array_keys($headers), function ($k) {
// Numeric array keys are converted to int by PHP.
@ -182,15 +258,16 @@ final class Message
return strtolower($k) === 'host';
});
// If no host is found, then a full URI cannot be constructed.
if (!$hostKey) {
return $path;
return null;
}
$host = $headers[reset($hostKey)][0];
$scheme = substr($host, -4) === ':443' ? 'https' : 'http';
if (!is_string($host) || Rfc7230::parseHostHeader($host) === null) {
throw new \InvalidArgumentException('Invalid request string');
}
return $scheme.'://'.$host.'/'.ltrim($path, '/');
return $host;
}
/**

View file

@ -29,8 +29,20 @@ trait MessageTrait
return $this->protocol;
}
/**
* @return static
*/
public function withProtocolVersion($version): MessageInterface
{
if (!\is_string($version)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to MessageInterface::withProtocolVersion() is deprecated; guzzlehttp/psr7 3.0 requires string.',
\get_debug_type($version)
);
}
if ($this->protocol === $version) {
return $this;
}
@ -69,9 +81,25 @@ trait MessageTrait
return implode(', ', $this->getHeader($header));
}
/**
* @return static
*/
public function withHeader($header, $value): MessageInterface
{
$this->assertHeader($header);
$values = \is_array($value) ? $value : [$value];
foreach ($values as $item) {
if (!\is_string($item) && (\is_scalar($item) || $item === null)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to MessageInterface::withHeader() is deprecated; guzzlehttp/psr7 3.0 requires string|string[].',
\get_debug_type($item)
);
break;
}
}
$value = $this->normalizeHeaderValue($value);
$normalized = strtolower($header);
@ -85,9 +113,25 @@ trait MessageTrait
return $new;
}
/**
* @return static
*/
public function withAddedHeader($header, $value): MessageInterface
{
$this->assertHeader($header);
$values = \is_array($value) ? $value : [$value];
foreach ($values as $item) {
if (!\is_string($item) && (\is_scalar($item) || $item === null)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to MessageInterface::withAddedHeader() is deprecated; guzzlehttp/psr7 3.0 requires string|string[].',
\get_debug_type($item)
);
break;
}
}
$value = $this->normalizeHeaderValue($value);
$normalized = strtolower($header);
@ -103,6 +147,9 @@ trait MessageTrait
return $new;
}
/**
* @return static
*/
public function withoutHeader($header): MessageInterface
{
$normalized = strtolower($header);
@ -128,6 +175,9 @@ trait MessageTrait
return $this->stream;
}
/**
* @return static
*/
public function withBody(StreamInterface $body): MessageInterface
{
if ($body === $this->stream) {
@ -151,6 +201,20 @@ trait MessageTrait
$header = (string) $header;
$this->assertHeader($header);
$values = \is_array($value) ? $value : [$value];
foreach ($values as $item) {
if (!\is_string($item) && (\is_scalar($item) || $item === null)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to %s::__construct() is deprecated; guzzlehttp/psr7 3.0 requires string|string[].',
\get_debug_type($item),
static::class
);
break;
}
}
$value = $this->normalizeHeaderValue($value);
$normalized = strtolower($header);
if (isset($this->headerNames[$normalized])) {
@ -170,6 +234,14 @@ trait MessageTrait
*/
private function normalizeHeaderValue($value): array
{
if (is_array($value) && $value === []) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing an empty array as a header value is deprecated; guzzlehttp/psr7 3.0 rejects empty header value arrays.'
);
}
if (!is_array($value)) {
return $this->trimAndValidateHeaderValues([$value]);
}

View file

@ -7,22 +7,23 @@ namespace GuzzleHttp\Psr7;
final class MimeType
{
private const MIME_TYPES = [
'123' => 'application/vnd.lotus-1-2-3',
'1km' => 'application/vnd.1000minds.decision-model+xml',
'210' => 'model/step',
'3dml' => 'text/vnd.in3d.3dml',
'3ds' => 'image/x-3ds',
'3g2' => 'video/3gpp2',
'3gp' => 'video/3gp',
'3gp' => 'video/3gpp',
'3gpp' => 'video/3gpp',
'3mf' => 'model/3mf',
'7z' => 'application/x-7z-compressed',
'7zip' => 'application/x-7z-compressed',
'123' => 'application/vnd.lotus-1-2-3',
'aab' => 'application/x-authorware-bin',
'aac' => 'audio/aac',
'aam' => 'application/x-authorware-map',
'aas' => 'application/x-authorware-seg',
'abw' => 'application/x-abiword',
'ac' => 'application/vnd.nokia.n-gage.ac+xml',
'ac' => 'application/pkix-attr-cert',
'ac3' => 'audio/ac3',
'acc' => 'application/vnd.americandynamics.acc',
'ace' => 'application/x-ace-compressed',
@ -35,7 +36,7 @@ final class MimeType
'afp' => 'application/vnd.ibm.modcap',
'age' => 'application/vnd.age',
'ahead' => 'application/vnd.ahead.space',
'ai' => 'application/pdf',
'ai' => 'application/postscript',
'aif' => 'audio/x-aiff',
'aifc' => 'audio/x-aiff',
'aiff' => 'audio/x-aiff',
@ -55,7 +56,7 @@ final class MimeType
'apr' => 'application/vnd.lotus-approach',
'arc' => 'application/x-freearc',
'arj' => 'application/x-arj',
'asc' => 'application/pgp-signature',
'asc' => 'application/pgp-keys',
'asf' => 'video/x-ms-asf',
'asm' => 'text/x-asm',
'aso' => 'application/vnd.accpac.simply.aso',
@ -66,7 +67,7 @@ final class MimeType
'atomdeleted' => 'application/atomdeleted+xml',
'atomsvc' => 'application/atomsvc+xml',
'atx' => 'application/vnd.antix.game-component',
'au' => 'audio/x-au',
'au' => 'audio/basic',
'avci' => 'image/avci',
'avcs' => 'image/avcs',
'avi' => 'video/x-msvideo',
@ -77,15 +78,18 @@ final class MimeType
'azv' => 'image/vnd.airzip.accelerator.azv',
'azw' => 'application/vnd.amazon.ebook',
'b16' => 'image/vnd.pco.b16',
'bary' => 'model/vnd.bary',
'bat' => 'application/x-msdownload',
'bcpio' => 'application/x-bcpio',
'bdf' => 'application/x-font-bdf',
'bdm' => 'application/vnd.syncml.dm+wbxml',
'bdoc' => 'application/x-bdoc',
'bdo' => 'application/vnd.nato.bindingdataobject+xml',
'bdoc' => 'application/bdoc',
'bed' => 'application/vnd.realvnc.bed',
'bh2' => 'application/vnd.fujitsu.oasysprs',
'bin' => 'application/octet-stream',
'blb' => 'application/x-blorb',
'blend' => 'application/x-blender',
'blorb' => 'application/x-blorb',
'bmi' => 'application/vnd.bmi',
'bmml' => 'application/vnd.balsamiq.bmml+xml',
@ -95,6 +99,8 @@ final class MimeType
'boz' => 'application/x-bzip2',
'bpk' => 'application/octet-stream',
'bpmn' => 'application/octet-stream',
'brush' => 'application/vnd.procreate.brush',
'brushset' => 'application/vnd.procreate.brushset',
'bsp' => 'model/vnd.valve.source.compiled-map',
'btf' => 'image/prs.btif',
'btif' => 'image/prs.btif',
@ -102,13 +108,13 @@ final class MimeType
'bz' => 'application/x-bzip',
'bz2' => 'application/x-bzip2',
'c' => 'text/x-c',
'c11amc' => 'application/vnd.cluetrust.cartomobile-config',
'c11amz' => 'application/vnd.cluetrust.cartomobile-config-pkg',
'c4d' => 'application/vnd.clonk.c4group',
'c4f' => 'application/vnd.clonk.c4group',
'c4g' => 'application/vnd.clonk.c4group',
'c4p' => 'application/vnd.clonk.c4group',
'c4u' => 'application/vnd.clonk.c4group',
'c11amc' => 'application/vnd.cluetrust.cartomobile-config',
'c11amz' => 'application/vnd.cluetrust.cartomobile-config-pkg',
'cab' => 'application/vnd.ms-cab-compressed',
'caf' => 'audio/x-caf',
'cap' => 'application/vnd.tcpdump.pcap',
@ -132,7 +138,6 @@ final class MimeType
'cdmid' => 'application/cdmi-domain',
'cdmio' => 'application/cdmi-object',
'cdmiq' => 'application/cdmi-queue',
'cdr' => 'application/cdr',
'cdx' => 'chemical/x-cdx',
'cdxml' => 'application/vnd.chemdraw+xml',
'cdy' => 'application/vnd.cinderella',
@ -147,7 +152,7 @@ final class MimeType
'cil' => 'application/vnd.ms-artgalry',
'cjs' => 'application/node',
'cla' => 'application/vnd.claymore',
'class' => 'application/octet-stream',
'class' => 'application/java-vm',
'cld' => 'model/vnd.cld',
'clkk' => 'application/vnd.crick.clicker.keyboard',
'clkp' => 'application/vnd.crick.clicker.palette',
@ -194,6 +199,8 @@ final class MimeType
'davmount' => 'application/davmount+xml',
'dbf' => 'application/vnd.dbf',
'dbk' => 'application/docbook+xml',
'dcm' => 'application/dicom',
'dcmp' => 'application/vnd.dcmp+xml',
'dcr' => 'application/x-director',
'dcurl' => 'text/vnd.curl.dcurl',
'dd2' => 'application/vnd.oma.dd2+xml',
@ -221,19 +228,22 @@ final class MimeType
'dmp' => 'application/vnd.tcpdump.pcap',
'dms' => 'application/octet-stream',
'dna' => 'application/vnd.dna',
'dng' => 'image/x-adobe-dng',
'doc' => 'application/msword',
'docm' => 'application/vnd.ms-word.template.macroEnabled.12',
'docm' => 'application/vnd.ms-word.document.macroenabled.12',
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'dot' => 'application/msword',
'dotm' => 'application/vnd.ms-word.template.macroEnabled.12',
'dotm' => 'application/vnd.ms-word.template.macroenabled.12',
'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
'dp' => 'application/vnd.osgi.dp',
'dpg' => 'application/vnd.dpgraph',
'dpx' => 'image/dpx',
'dra' => 'audio/vnd.dra',
'drle' => 'image/dicom-rle',
'drm' => 'application/vnd.procreate.dream',
'dsc' => 'text/prs.lines.tag',
'dssc' => 'application/dssc+der',
'dst' => 'application/octet-stream',
'dtb' => 'application/x-dtbook+xml',
'dtd' => 'application/xml-dtd',
'dts' => 'audio/vnd.dts',
@ -285,10 +295,12 @@ final class MimeType
'f4v' => 'video/mp4',
'f77' => 'text/x-fortran',
'f90' => 'text/x-fortran',
'facti' => 'image/vnd.blockfact.facti',
'fbs' => 'image/vnd.fastbidsheet',
'fbx' => 'application/vnd.autodesk.fbx',
'fcdt' => 'application/vnd.adobe.formscentral.fcdt',
'fcs' => 'application/vnd.isac.fcs',
'fdf' => 'application/vnd.fdf',
'fdf' => 'application/fdf',
'fdt' => 'application/fdt+xml',
'fe_launch' => 'application/vnd.denovo.fcselayout-link',
'fg5' => 'application/vnd.fujitsu.oasysgp',
@ -330,21 +342,25 @@ final class MimeType
'gca' => 'application/x-gca-compressed',
'gdl' => 'model/vnd.gdl',
'gdoc' => 'application/vnd.google-apps.document',
'gdraw' => 'application/vnd.google-apps.drawing',
'ged' => 'text/vnd.familysearch.gedcom',
'geo' => 'application/vnd.dynageo',
'geojson' => 'application/geo+json',
'gex' => 'application/vnd.geometry-explorer',
'gform' => 'application/vnd.google-apps.form',
'ggb' => 'application/vnd.geogebra.file',
'ggs' => 'application/vnd.geogebra.slides',
'ggt' => 'application/vnd.geogebra.tool',
'ghf' => 'application/vnd.groove-help',
'gif' => 'image/gif',
'gim' => 'application/vnd.groove-identity-message',
'gjam' => 'application/vnd.google-apps.jam',
'glb' => 'model/gltf-binary',
'gltf' => 'model/gltf+json',
'gmap' => 'application/vnd.google-apps.map',
'gml' => 'application/gml+xml',
'gmx' => 'application/vnd.gmx',
'gnumeric' => 'application/x-gnumeric',
'gpg' => 'application/gpg-keys',
'gph' => 'application/vnd.flographit',
'gpx' => 'application/gpx+xml',
'gqf' => 'application/vnd.grafeq',
@ -354,8 +370,10 @@ final class MimeType
'gre' => 'application/vnd.geometry-explorer',
'grv' => 'application/vnd.groove-injector',
'grxml' => 'application/srgs+xml',
'gscript' => 'application/vnd.google-apps.script',
'gsf' => 'application/x-font-ghostscript',
'gsheet' => 'application/vnd.google-apps.spreadsheet',
'gsite' => 'application/vnd.google-apps.site',
'gslides' => 'application/vnd.google-apps.presentation',
'gtar' => 'application/x-gtar',
'gtm' => 'application/vnd.groove-tool-message',
@ -387,7 +405,6 @@ final class MimeType
'hpid' => 'application/vnd.hp-hpid',
'hps' => 'application/vnd.hp-hps',
'hqx' => 'application/mac-binhex40',
'hsj2' => 'image/hsj2',
'htc' => 'text/x-component',
'htke' => 'application/vnd.kenameaapp',
'htm' => 'text/html',
@ -399,7 +416,7 @@ final class MimeType
'icc' => 'application/vnd.iccprofile',
'ice' => 'x-conference/x-cooltalk',
'icm' => 'application/vnd.iccprofile',
'ico' => 'image/x-icon',
'ico' => 'image/vnd.microsoft.icon',
'ics' => 'text/calendar',
'ief' => 'image/ief',
'ifb' => 'text/calendar',
@ -414,6 +431,7 @@ final class MimeType
'imp' => 'application/vnd.accpac.simply.imp',
'ims' => 'application/vnd.ms-ims',
'in' => 'text/plain',
'indd' => 'application/x-indesign',
'ini' => 'text/plain',
'ink' => 'application/inkml+xml',
'inkml' => 'application/inkml+xml',
@ -421,6 +439,7 @@ final class MimeType
'iota' => 'application/vnd.astraea-software.iota',
'ipfix' => 'application/ipfix',
'ipk' => 'application/vnd.shana.informed.package',
'ipynb' => 'application/x-ipynb+json',
'irm' => 'application/vnd.ibm.rights-management',
'irp' => 'application/vnd.irepository.package+xml',
'iso' => 'application/x-iso9660-image',
@ -430,10 +449,13 @@ final class MimeType
'ivu' => 'application/vnd.immervision-ivu',
'jad' => 'text/vnd.sun.j2me.app-descriptor',
'jade' => 'text/jade',
'jaii' => 'image/jaii',
'jais' => 'image/jais',
'jam' => 'application/vnd.jam',
'jar' => 'application/java-archive',
'jardiff' => 'application/x-java-archive-diff',
'java' => 'text/x-java-source',
'jfif' => 'image/jpeg',
'jhc' => 'image/jphc',
'jisp' => 'application/vnd.jisp',
'jls' => 'image/jls',
@ -447,18 +469,19 @@ final class MimeType
'jpf' => 'image/jpx',
'jpg' => 'image/jpeg',
'jpg2' => 'image/jp2',
'jpgm' => 'video/jpm',
'jpgm' => 'image/jpm',
'jpgv' => 'video/jpeg',
'jph' => 'image/jph',
'jpm' => 'video/jpm',
'jpm' => 'image/jpm',
'jpx' => 'image/jpx',
'js' => 'application/javascript',
'js' => 'text/javascript',
'json' => 'application/json',
'json5' => 'application/json5',
'jsonld' => 'application/ld+json',
'jsonml' => 'application/jsonml+json',
'jsx' => 'text/jsx',
'jt' => 'model/jt',
'jxl' => 'image/jxl',
'jxr' => 'image/jxr',
'jxra' => 'image/jxra',
'jxrs' => 'image/jxrs',
@ -468,9 +491,10 @@ final class MimeType
'jxss' => 'image/jxss',
'kar' => 'audio/midi',
'karbon' => 'application/vnd.kde.karbon',
'kbl' => 'application/kbl+xml',
'kdb' => 'application/octet-stream',
'kdbx' => 'application/x-keepass2',
'key' => 'application/x-iwork-keynote-sffkey',
'key' => 'application/vnd.apple.keynote',
'kfo' => 'application/vnd.kde.kformula',
'kia' => 'application/vnd.kidspiration',
'kml' => 'application/vnd.google-earth.kml+xml',
@ -495,7 +519,7 @@ final class MimeType
'les' => 'application/vnd.hhe.lesson-player',
'less' => 'text/less',
'lgr' => 'application/lgr+xml',
'lha' => 'application/octet-stream',
'lha' => 'application/x-lzh-compressed',
'link66' => 'application/vnd.route66.link66+xml',
'list' => 'text/plain',
'list3820' => 'application/vnd.ibm.modcap',
@ -504,6 +528,7 @@ final class MimeType
'lnk' => 'application/x-ms-shortcut',
'log' => 'text/plain',
'lostxml' => 'application/lost+xml',
'lottie' => 'application/zip+dotlottie',
'lrf' => 'application/octet-stream',
'lrm' => 'application/vnd.ms-lrm',
'ltf' => 'application/vnd.frogans.ltf',
@ -511,21 +536,24 @@ final class MimeType
'luac' => 'application/x-lua-bytecode',
'lvp' => 'audio/vnd.lucent.voice',
'lwp' => 'application/vnd.lotus-wordpro',
'lzh' => 'application/octet-stream',
'm1v' => 'video/mpeg',
'm2a' => 'audio/mpeg',
'm2v' => 'video/mpeg',
'm3a' => 'audio/mpeg',
'm3u' => 'text/plain',
'm3u8' => 'application/vnd.apple.mpegurl',
'm4a' => 'audio/x-m4a',
'm4p' => 'application/mp4',
'm4s' => 'video/iso.segment',
'm4u' => 'application/vnd.mpegurl',
'm4v' => 'video/x-m4v',
'lzh' => 'application/x-lzh-compressed',
'm13' => 'application/x-msmediaview',
'm14' => 'application/x-msmediaview',
'm1v' => 'video/mpeg',
'm21' => 'application/mp21',
'm2a' => 'audio/mpeg',
'm2t' => 'video/mp2t',
'm2ts' => 'video/mp2t',
'm2v' => 'video/mpeg',
'm3a' => 'audio/mpeg',
'm3u' => 'audio/x-mpegurl',
'm3u8' => 'application/vnd.apple.mpegurl',
'm4a' => 'audio/mp4',
'm4b' => 'audio/mp4',
'm4p' => 'application/mp4',
'm4s' => 'video/iso.segment',
'm4u' => 'video/vnd.mpegurl',
'm4v' => 'video/x-m4v',
'ma' => 'application/mathematica',
'mads' => 'application/mads+xml',
'maei' => 'application/mmt-aei+xml',
@ -556,6 +584,8 @@ final class MimeType
'mft' => 'application/rpki-manifest',
'mgp' => 'application/vnd.osgeo.mapguide.package',
'mgz' => 'application/vnd.proteus.magazine',
'mht' => 'message/rfc822',
'mhtml' => 'message/rfc822',
'mid' => 'audio/midi',
'midi' => 'audio/midi',
'mie' => 'application/x-mie',
@ -564,11 +594,11 @@ final class MimeType
'mj2' => 'video/mj2',
'mjp2' => 'video/mj2',
'mjs' => 'text/javascript',
'mk3d' => 'video/x-matroska',
'mka' => 'audio/x-matroska',
'mk3d' => 'video/matroska-3d',
'mka' => 'audio/matroska',
'mkd' => 'text/x-markdown',
'mks' => 'video/x-matroska',
'mkv' => 'video/x-matroska',
'mkv' => 'video/matroska',
'mlp' => 'application/vnd.dolby.mlp',
'mmd' => 'application/vnd.chipnuts.karaoke-mmd',
'mmf' => 'application/vnd.smaf',
@ -581,13 +611,13 @@ final class MimeType
'mov' => 'video/quicktime',
'movie' => 'video/x-sgi-movie',
'mp2' => 'audio/mpeg',
'mp21' => 'application/mp21',
'mp2a' => 'audio/mpeg',
'mp3' => 'audio/mpeg',
'mp4' => 'video/mp4',
'mp4a' => 'audio/mp4',
'mp4s' => 'application/mp4',
'mp4v' => 'video/mp4',
'mp21' => 'application/mp21',
'mpc' => 'application/vnd.mophun.certificate',
'mpd' => 'application/dash+xml',
'mpe' => 'video/mpeg',
@ -612,7 +642,7 @@ final class MimeType
'msf' => 'application/vnd.epson.msf',
'msg' => 'application/vnd.ms-outlook',
'msh' => 'model/mesh',
'msi' => 'application/x-msdownload',
'msi' => 'application/octet-stream',
'msix' => 'application/msix',
'msixbundle' => 'application/msixbundle',
'msl' => 'application/vnd.mobius.msl',
@ -620,7 +650,7 @@ final class MimeType
'msp' => 'application/octet-stream',
'msty' => 'application/vnd.muvee.style',
'mtl' => 'model/mtl',
'mts' => 'model/vnd.mts',
'mts' => 'video/mp2t',
'mus' => 'application/vnd.musician',
'musd' => 'application/mmt-usd+xml',
'musicxml' => 'application/vnd.recordare.musicxml+xml',
@ -639,6 +669,7 @@ final class MimeType
'nbp' => 'application/vnd.wolfram.player',
'nc' => 'application/x-netcdf',
'ncx' => 'application/x-dtbncx+xml',
'ndjson' => 'application/x-ndjson',
'nfo' => 'text/x-nfo',
'ngdat' => 'application/vnd.nokia.n-gage.data',
'nitf' => 'application/vnd.nitf',
@ -653,7 +684,7 @@ final class MimeType
'nsf' => 'application/vnd.lotus-notes',
'nt' => 'application/n-triples',
'ntf' => 'application/vnd.nitf',
'numbers' => 'application/x-iwork-numbers-sffnumbers',
'numbers' => 'application/vnd.apple.numbers',
'nzb' => 'application/x-nzb',
'oa2' => 'application/vnd.fujitsu.oasys2',
'oa3' => 'application/vnd.fujitsu.oasys3',
@ -678,6 +709,8 @@ final class MimeType
'ogv' => 'video/ogg',
'ogx' => 'application/ogg',
'omdoc' => 'application/omdoc+xml',
'one' => 'application/onenote',
'onea' => 'application/onenote',
'onepkg' => 'application/onenote',
'onetmp' => 'application/onenote',
'onetoc' => 'application/onenote',
@ -686,7 +719,7 @@ final class MimeType
'opml' => 'text/x-opml',
'oprc' => 'application/vnd.palm',
'opus' => 'audio/ogg',
'org' => 'text/x-org',
'org' => 'application/vnd.lotus-organizer',
'osf' => 'application/vnd.yamaha.openscoreformat',
'osfpvg' => 'application/vnd.yamaha.openscoreformat.osfpvg+xml',
'osm' => 'application/vnd.openstreetmap.data+xml',
@ -704,17 +737,20 @@ final class MimeType
'oxps' => 'application/oxps',
'oxt' => 'application/vnd.openofficeorg.extension',
'p' => 'text/x-pascal',
'p10' => 'application/pkcs10',
'p12' => 'application/x-pkcs12',
'p21' => 'model/step',
'p7a' => 'application/x-pkcs7-signature',
'p7b' => 'application/x-pkcs7-certificates',
'p7c' => 'application/pkcs7-mime',
'p7e' => 'application/pkcs7-mime',
'p7m' => 'application/pkcs7-mime',
'p7r' => 'application/x-pkcs7-certreqresp',
'p7s' => 'application/pkcs7-signature',
'p8' => 'application/pkcs8',
'p10' => 'application/x-pkcs10',
'p12' => 'application/x-pkcs12',
'pac' => 'application/x-ns-proxy-autoconfig',
'pages' => 'application/x-iwork-pages-sffpages',
'pages' => 'application/vnd.apple.pages',
'parquet' => 'application/vnd.apache.parquet',
'pas' => 'text/x-pascal',
'paw' => 'application/vnd.pawaafile',
'pbd' => 'application/vnd.powerbuilder6',
@ -725,8 +761,8 @@ final class MimeType
'pclxl' => 'application/vnd.hp-pclxl',
'pct' => 'image/x-pict',
'pcurl' => 'application/vnd.curl.pcurl',
'pcx' => 'image/x-pcx',
'pdb' => 'application/x-pilot',
'pcx' => 'image/vnd.zbrush.pcx',
'pdb' => 'application/vnd.palm',
'pde' => 'text/x-processing',
'pdf' => 'application/pdf',
'pem' => 'application/x-x509-user-cert',
@ -737,7 +773,7 @@ final class MimeType
'pfx' => 'application/x-pkcs12',
'pgm' => 'image/x-portable-graymap',
'pgn' => 'application/x-chess-pgn',
'pgp' => 'application/pgp',
'pgp' => 'application/pgp-encrypted',
'phar' => 'application/octet-stream',
'php' => 'application/x-httpd-php',
'php3' => 'application/x-httpd-php',
@ -760,17 +796,17 @@ final class MimeType
'pnm' => 'image/x-portable-anymap',
'portpkg' => 'application/vnd.macports.portpkg',
'pot' => 'application/vnd.ms-powerpoint',
'potm' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
'potm' => 'application/vnd.ms-powerpoint.template.macroenabled.12',
'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template',
'ppa' => 'application/vnd.ms-powerpoint',
'ppam' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12',
'ppam' => 'application/vnd.ms-powerpoint.addin.macroenabled.12',
'ppd' => 'application/vnd.cups-ppd',
'ppm' => 'image/x-portable-pixmap',
'pps' => 'application/vnd.ms-powerpoint',
'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12',
'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroenabled.12',
'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
'ppt' => 'application/powerpoint',
'pptm' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
'ppt' => 'application/vnd.ms-powerpoint',
'pptm' => 'application/vnd.ms-powerpoint.presentation.macroenabled.12',
'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
'pqa' => 'application/vnd.palm',
'prc' => 'model/prc',
@ -779,14 +815,16 @@ final class MimeType
'provx' => 'application/provenance+xml',
'ps' => 'application/postscript',
'psb' => 'application/vnd.3gpp.pic-bw-small',
'psd' => 'application/x-photoshop',
'psd' => 'image/vnd.adobe.photoshop',
'psf' => 'application/x-font-linux-psf',
'pskcxml' => 'application/pskc+xml',
'pti' => 'image/prs.pti',
'ptid' => 'application/vnd.pvi.ptid1',
'pub' => 'application/x-mspublisher',
'pv' => 'application/octet-stream',
'pvb' => 'application/vnd.3gpp.pic-bw-var',
'pwn' => 'application/vnd.3m.post-it-notes',
'pxf' => 'application/octet-stream',
'pya' => 'audio/vnd.ms-playready.media.pya',
'pyo' => 'model/vnd.pytha.pyox',
'pyox' => 'model/vnd.pytha.pyox',
@ -806,7 +844,7 @@ final class MimeType
'ram' => 'audio/x-pn-realaudio',
'raml' => 'application/raml+yaml',
'rapd' => 'application/route-apd+xml',
'rar' => 'application/x-rar',
'rar' => 'application/vnd.rar',
'ras' => 'image/x-cmu-raster',
'rcprofile' => 'application/vnd.ipunplugged.rcprofile',
'rdf' => 'application/rdf+xml',
@ -821,7 +859,7 @@ final class MimeType
'rl' => 'application/resource-lists+xml',
'rlc' => 'image/vnd.fujixerox.edmics-rlc',
'rld' => 'application/resource-lists-diff+xml',
'rm' => 'audio/x-pn-realaudio',
'rm' => 'application/vnd.rn-realmedia',
'rmi' => 'audio/midi',
'rmp' => 'audio/x-pn-realaudio-plugin',
'rms' => 'application/vnd.jcp.javame.midlet-rms',
@ -831,7 +869,7 @@ final class MimeType
'roa' => 'application/rpki-roa',
'roff' => 'text/troff',
'rp9' => 'application/vnd.cloanto.rp9',
'rpm' => 'audio/x-pn-realaudio-plugin',
'rpm' => 'application/x-redhat-package-manager',
'rpss' => 'application/vnd.nokia.radio-presets',
'rpst' => 'application/vnd.nokia.radio-preset',
'rq' => 'application/sparql-query',
@ -865,7 +903,7 @@ final class MimeType
'sdkm' => 'application/vnd.solent.sdkm+xml',
'sdp' => 'application/sdp',
'sdw' => 'application/vnd.stardivision.writer',
'sea' => 'application/octet-stream',
'sea' => 'application/x-sea',
'see' => 'application/vnd.seemail',
'seed' => 'application/vnd.fdsn.seed',
'sema' => 'application/vnd.sema',
@ -910,8 +948,8 @@ final class MimeType
'slt' => 'application/vnd.epson.salt',
'sm' => 'application/vnd.stepmania.stepchart',
'smf' => 'application/vnd.stardivision.math',
'smi' => 'application/smil',
'smil' => 'application/smil',
'smi' => 'application/smil+xml',
'smil' => 'application/smil+xml',
'smv' => 'video/x-smv',
'smzip' => 'application/vnd.stepmania.package',
'snd' => 'audio/basic',
@ -925,7 +963,9 @@ final class MimeType
'spp' => 'application/scvp-vp-response',
'spq' => 'application/scvp-vp-request',
'spx' => 'audio/ogg',
'sql' => 'application/x-sql',
'sql' => 'application/sql',
'sqlite' => 'application/vnd.sqlite3',
'sqlite3' => 'application/vnd.sqlite3',
'src' => 'application/x-wais-source',
'srt' => 'application/x-subrip',
'sru' => 'application/sru+xml',
@ -938,12 +978,13 @@ final class MimeType
'st' => 'application/vnd.sailingtracker.track',
'stc' => 'application/vnd.sun.xml.calc.template',
'std' => 'application/vnd.sun.xml.draw.template',
'step' => 'application/STEP',
'step' => 'model/step',
'stf' => 'application/vnd.wt.stf',
'sti' => 'application/vnd.sun.xml.impress.template',
'stk' => 'application/hyperstudio',
'stl' => 'model/stl',
'stp' => 'application/STEP',
'stp' => 'model/step',
'stpnc' => 'model/step',
'stpx' => 'model/step+xml',
'stpxz' => 'model/step-xml+zip',
'stpz' => 'model/step+zip',
@ -951,7 +992,7 @@ final class MimeType
'stw' => 'application/vnd.sun.xml.writer.template',
'styl' => 'text/stylus',
'stylus' => 'text/stylus',
'sub' => 'text/vnd.dvb.subtitle',
'sub' => 'image/vnd.dvb.subtitle',
'sus' => 'application/vnd.sus-calendar',
'susp' => 'application/vnd.sus-calendar',
'sv4cpio' => 'application/x-sv4cpio',
@ -970,6 +1011,7 @@ final class MimeType
'sxi' => 'application/vnd.sun.xml.impress',
'sxm' => 'application/vnd.sun.xml.math',
'sxw' => 'application/vnd.sun.xml.writer',
'systemverify' => 'application/vnd.pp.systemverify+xml',
't' => 'text/troff',
't3' => 'application/x-t3vm-image',
't38' => 'image/t38',
@ -991,7 +1033,7 @@ final class MimeType
'tfm' => 'application/x-tex-tfm',
'tfx' => 'image/tiff-fx',
'tga' => 'image/x-tga',
'tgz' => 'application/x-tar',
'tgz' => 'application/gzip',
'thmx' => 'application/vnd.ms-officetheme',
'tif' => 'image/tiff',
'tiff' => 'image/tiff',
@ -1017,12 +1059,12 @@ final class MimeType
'txd' => 'application/vnd.genomatix.tuxedo',
'txf' => 'application/vnd.mobius.txf',
'txt' => 'text/plain',
'u32' => 'application/x-authorware-bin',
'u3d' => 'model/u3d',
'u8dsn' => 'message/global-delivery-status',
'u8hdr' => 'message/global-headers',
'u8mdn' => 'message/global-disposition-notification',
'u8msg' => 'message/global',
'u32' => 'application/x-authorware-bin',
'ubj' => 'application/ubjson',
'udeb' => 'application/x-debian-package',
'ufd' => 'application/vnd.ufdl',
@ -1078,16 +1120,18 @@ final class MimeType
'vcx' => 'application/vnd.vcx',
'vdi' => 'application/x-virtualbox-vdi',
'vds' => 'model/vnd.sap.vds',
'vdx' => 'application/vnd.ms-visio.viewer',
'vec' => 'application/vec+xml',
'vhd' => 'application/x-virtualbox-vhd',
'vis' => 'application/vnd.visionary',
'viv' => 'video/vnd.vivo',
'vlc' => 'application/videolan',
'vmdk' => 'application/x-virtualbox-vmdk',
'vob' => 'video/x-ms-vob',
'vor' => 'application/vnd.stardivision.writer',
'vox' => 'application/x-authorware-bin',
'vrml' => 'model/vrml',
'vsd' => 'application/vnd.visio',
'vsdx' => 'application/vnd.visio',
'vsf' => 'application/vnd.vsf',
'vss' => 'application/vnd.visio',
'vst' => 'application/vnd.visio',
@ -1095,17 +1139,18 @@ final class MimeType
'vtf' => 'image/vnd.valve.source.texture',
'vtt' => 'text/vtt',
'vtu' => 'model/vnd.vtu',
'vtx' => 'application/vnd.visio',
'vxml' => 'application/voicexml+xml',
'w3d' => 'application/x-director',
'wad' => 'application/x-doom',
'wadl' => 'application/vnd.sun.wadl+xml',
'war' => 'application/java-archive',
'wasm' => 'application/wasm',
'wav' => 'audio/x-wav',
'wav' => 'audio/wav',
'wax' => 'audio/x-ms-wax',
'wbmp' => 'image/vnd.wap.wbmp',
'wbs' => 'application/vnd.criticaltools.wbs+xml',
'wbxml' => 'application/wbxml',
'wbxml' => 'application/vnd.wap.wbxml',
'wcm' => 'application/vnd.ms-works',
'wdb' => 'application/vnd.ms-works',
'wdp' => 'image/vnd.ms-photo',
@ -1124,12 +1169,12 @@ final class MimeType
'wmd' => 'application/x-ms-wmd',
'wmf' => 'image/wmf',
'wml' => 'text/vnd.wap.wml',
'wmlc' => 'application/wmlc',
'wmlc' => 'application/vnd.wap.wmlc',
'wmls' => 'text/vnd.wap.wmlscript',
'wmlsc' => 'application/vnd.wap.wmlscriptc',
'wmv' => 'video/x-ms-wmv',
'wmx' => 'video/x-ms-wmx',
'wmz' => 'application/x-msmetafile',
'wmz' => 'application/x-ms-wmz',
'woff' => 'font/woff',
'woff2' => 'font/woff2',
'word' => 'application/msword',
@ -1144,13 +1189,13 @@ final class MimeType
'wspolicy' => 'application/wspolicy+xml',
'wtb' => 'application/vnd.webturbo',
'wvx' => 'video/x-ms-wvx',
'x32' => 'application/x-authorware-bin',
'x3d' => 'model/x3d+xml',
'x3db' => 'model/x3d+fastinfoset',
'x3dbz' => 'model/x3d+binary',
'x3dv' => 'model/x3d-vrml',
'x3dvz' => 'model/x3d+vrml',
'x3dz' => 'model/x3d+xml',
'x32' => 'application/x-authorware-bin',
'x_b' => 'model/vnd.parasolid.transmit.binary',
'x_t' => 'model/vnd.parasolid.transmit.text',
'xaml' => 'application/xaml+xml',
@ -1162,6 +1207,7 @@ final class MimeType
'xbm' => 'image/x-xbitmap',
'xca' => 'application/xcap-caps+xml',
'xcs' => 'application/calendar+xml',
'xdcf' => 'application/vnd.gov.sk.xmldatacontainer+xml',
'xdf' => 'application/xcap-diff+xml',
'xdm' => 'application/vnd.syncml.dm+xml',
'xdp' => 'application/vnd.adobe.xdp+xml',
@ -1177,18 +1223,18 @@ final class MimeType
'xhtml' => 'application/xhtml+xml',
'xhvml' => 'application/xv+xml',
'xif' => 'image/vnd.xiff',
'xl' => 'application/excel',
'xl' => 'application/vnd.ms-excel',
'xla' => 'application/vnd.ms-excel',
'xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12',
'xlam' => 'application/vnd.ms-excel.addin.macroenabled.12',
'xlc' => 'application/vnd.ms-excel',
'xlf' => 'application/xliff+xml',
'xlm' => 'application/vnd.ms-excel',
'xls' => 'application/vnd.ms-excel',
'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
'xlsm' => 'application/vnd.ms-excel.sheet.macroEnabled.12',
'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroenabled.12',
'xlsm' => 'application/vnd.ms-excel.sheet.macroenabled.12',
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'xlt' => 'application/vnd.ms-excel',
'xltm' => 'application/vnd.ms-excel.template.macroEnabled.12',
'xltm' => 'application/vnd.ms-excel.template.macroenabled.12',
'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
'xlw' => 'application/vnd.ms-excel',
'xm' => 'audio/xm',
@ -1205,7 +1251,7 @@ final class MimeType
'xpx' => 'application/vnd.intercon.formnet',
'xsd' => 'application/xml',
'xsf' => 'application/prs.xsf+xml',
'xsl' => 'application/xml',
'xsl' => 'application/xslt+xml',
'xslt' => 'application/xslt+xml',
'xsm' => 'application/vnd.syncml+xml',
'xspf' => 'application/xspf+xml',

View file

@ -20,20 +20,36 @@ final class MultipartStream implements StreamInterface
/** @var StreamInterface */
private $stream;
private const BOUNDARY_CHARS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'()+_,-./:=? ";
/**
* @param array $elements Array of associative arrays, each containing a
* required "name" key mapping to the form field,
* name, a required "contents" key mapping to a
* StreamInterface/resource/string, an optional
* "headers" associative array of custom headers,
* and an optional "filename" key mapping to a
* string to send as the filename in the part.
* @param string $boundary You can optionally provide a specific boundary
* @param array $elements Array of associative arrays, each containing a
* required "name" key mapping to the form field,
* name, a required "contents" key mapping to any
* non-array value accepted by Utils::streamFor(),
* or an array for nested expansion.
* Optional keys include "headers" (associative
* array of custom headers) and "filename" (string
* to send as the filename in the part).
* When "contents" is an array, it is recursively
* expanded into multiple fields using bracket notation
* (e.g., name[0][key]). Empty arrays produce no fields.
* The "filename" and "headers" options cannot be used
* with array contents.
* @param string|null $boundary You can optionally provide a specific boundary
*
* @throws \InvalidArgumentException
*/
public function __construct(array $elements = [], ?string $boundary = null)
{
if ($boundary !== null && !self::isValidBoundary($boundary)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing an invalid multipart boundary to MultipartStream::__construct() is deprecated; guzzlehttp/psr7 3.0 rejects invalid multipart boundaries.'
);
}
$this->boundary = $boundary ?: bin2hex(random_bytes(20));
$this->stream = $this->createStream($elements);
}
@ -51,12 +67,13 @@ final class MultipartStream implements StreamInterface
/**
* Get the headers needed before transferring the content of a POST file
*
* @param string[] $headers
* @param array<array-key, string> $headers
*/
private function getHeaders(array $headers): string
{
$str = '';
foreach ($headers as $key => $value) {
$key = (string) $key;
$str .= "{$key}: {$value}\r\n";
}
@ -91,6 +108,22 @@ final class MultipartStream implements StreamInterface
}
}
if (!is_string($element['name']) && !is_int($element['name'])) {
throw new \InvalidArgumentException("The 'name' key must be a string or integer");
}
if (is_array($element['contents'])) {
if (array_key_exists('filename', $element) || array_key_exists('headers', $element)) {
throw new \InvalidArgumentException(
"The 'filename' and 'headers' options cannot be used when 'contents' is an array"
);
}
$this->addNestedElements($stream, $element['contents'], (string) $element['name']);
return;
}
$element['contents'] = Utils::streamFor($element['contents']);
if (empty($element['filename'])) {
@ -101,7 +134,7 @@ final class MultipartStream implements StreamInterface
}
[$body, $headers] = $this->createElement(
$element['name'],
(string) $element['name'],
$element['contents'],
$element['filename'] ?? null,
$element['headers'] ?? []
@ -113,12 +146,32 @@ final class MultipartStream implements StreamInterface
}
/**
* @param string[] $headers
* Recursively expand array contents into multiple form fields.
*
* @return array{0: StreamInterface, 1: string[]}
* @param array<array-key, mixed> $contents
*/
private function addNestedElements(AppendStream $stream, array $contents, string $root): void
{
foreach ($contents as $key => $value) {
$fieldName = $root === '' ? sprintf('[%s]', (string) $key) : sprintf('%s[%s]', $root, (string) $key);
if (is_array($value)) {
$this->addNestedElements($stream, $value, $fieldName);
} else {
$this->addElement($stream, ['name' => $fieldName, 'contents' => $value]);
}
}
}
/**
* @param array<array-key, mixed> $headers
*
* @return array{0: StreamInterface, 1: array<array-key, string>}
*/
private function createElement(string $name, StreamInterface $stream, ?string $filename, array $headers): array
{
$headers = self::normalizePartHeaders($headers);
// Set a default content-disposition header if one was no provided
$disposition = self::getHeader($headers, 'content-disposition');
if (!$disposition) {
@ -149,7 +202,7 @@ final class MultipartStream implements StreamInterface
}
/**
* @param string[] $headers
* @param array<array-key, string> $headers
*/
private static function getHeader(array $headers, string $key): ?string
{
@ -162,4 +215,75 @@ final class MultipartStream implements StreamInterface
return null;
}
private static function isValidBoundary(string $boundary): bool
{
$length = strlen($boundary);
if ($length < 1 || $length > 70 || $boundary[$length - 1] === ' ') {
return false;
}
return strspn($boundary, self::BOUNDARY_CHARS) === $length;
}
/**
* @param array<array-key, mixed> $headers
*
* @return array<array-key, string>
*/
private static function normalizePartHeaders(array $headers): array
{
$normalized = [];
foreach ($headers as $key => $value) {
self::deprecateInvalidPartHeaderName((string) $key);
if (!is_string($value)) {
if (!is_scalar($value) && $value !== null && !(is_object($value) && method_exists($value, '__toString'))) {
throw new \InvalidArgumentException(sprintf(
'Multipart part header value must be a string or stringable value but %s provided.',
\get_debug_type($value)
));
}
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s as a multipart part header value is deprecated; guzzlehttp/psr7 3.0 requires string multipart part header values.',
\get_debug_type($value)
);
}
$value = (string) $value;
self::deprecateInvalidPartHeaderValue($value);
$normalized[$key] = $value;
}
return $normalized;
}
private static function deprecateInvalidPartHeaderName(string $name): void
{
if (!preg_match('/^[a-zA-Z0-9\'`#$%&*+.^_|~!-]+$/D', $name)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing an invalid multipart part header name to MultipartStream is deprecated; guzzlehttp/psr7 3.0 rejects invalid multipart part header names.'
);
}
}
private static function deprecateInvalidPartHeaderValue(string $value): void
{
if (!preg_match('/^[\x20\x09\x21-\x7E\x80-\xFF]*$/D', $value)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing an invalid multipart part header value to MultipartStream is deprecated; guzzlehttp/psr7 3.0 rejects invalid multipart part header values.'
);
}
}
}

View file

@ -18,6 +18,24 @@ final class NoSeekStream implements StreamInterface
public function seek($offset, $whence = SEEK_SET): void
{
if (!\is_int($offset)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to StreamInterface::seek() is deprecated; guzzlehttp/psr7 3.0 requires int for $offset.',
\get_debug_type($offset)
);
}
if (!\is_int($whence)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to StreamInterface::seek() is deprecated; guzzlehttp/psr7 3.0 requires int for $whence.',
\get_debug_type($whence)
);
}
throw new \RuntimeException('Cannot seek a NoSeekStream');
}

View file

@ -9,16 +9,19 @@ use Psr\Http\Message\StreamInterface;
/**
* Provides a read only stream that pumps data from a PHP callable.
*
* When invoking the provided callable, the PumpStream will pass the amount of
* data requested to read to the callable. The callable can choose to ignore
* When invoking the provided callable, the PumpStream will pass the suggested
* number of bytes to read to the callable. The callable can choose to ignore
* this value and return fewer or more bytes than requested. Any extra data
* returned by the provided callable is buffered internally until drained using
* the read() function of the PumpStream. The provided callable MUST return
* false when there is no more data to read.
* returned by the callable is buffered internally until drained using the
* read() function of the PumpStream. The callable MUST return false or null
* when there is no more data to read.
*
* Userland callables that declare no parameters are tolerated by PHP, but
* length-aware callables remain the recommended formal shape.
*/
final class PumpStream implements StreamInterface
{
/** @var callable(int): (string|false|null)|null */
/** @var callable|null */
private $source;
/** @var int|null */
@ -34,14 +37,17 @@ final class PumpStream implements StreamInterface
private $buffer;
/**
* @param callable(int): (string|false|null) $source Source of the stream data. The callable MAY
* accept an integer argument used to control the
* amount of data to return. The callable MUST
* return a string when called, or false|null on error
* or EOF.
* @param array{size?: int, metadata?: array} $options Stream options:
* - metadata: Hash of metadata to use with stream.
* - size: Size of the stream, if known.
* @param (callable(): (string|false|null))|(callable(int): (string|false|null)) $source Source of the stream data. The callable receives
* the suggested number of bytes to read, may ignore
* that value, and may return fewer or more bytes.
* Extra bytes are buffered. The callable MUST return
* a string when called, or false|null on error or EOF.
* Userland callables that declare no parameters are
* tolerated by PHP, but length-aware callables remain
* the recommended formal shape.
* @param array{size?: int, metadata?: array} $options Stream options:
* - metadata: Hash of metadata to use with stream.
* - size: Size of the stream, if known.
*/
public function __construct(callable $source, array $options = [])
{
@ -105,6 +111,24 @@ final class PumpStream implements StreamInterface
public function seek($offset, $whence = SEEK_SET): void
{
if (!\is_int($offset)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to StreamInterface::seek() is deprecated; guzzlehttp/psr7 3.0 requires int for $offset.',
\get_debug_type($offset)
);
}
if (!\is_int($whence)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to StreamInterface::seek() is deprecated; guzzlehttp/psr7 3.0 requires int for $whence.',
\get_debug_type($whence)
);
}
throw new \RuntimeException('Cannot seek a PumpStream');
}
@ -115,6 +139,15 @@ final class PumpStream implements StreamInterface
public function write($string): int
{
if (!\is_string($string)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to StreamInterface::write() is deprecated; guzzlehttp/psr7 3.0 requires string for $string.',
\get_debug_type($string)
);
}
throw new \RuntimeException('Cannot write to a PumpStream');
}
@ -125,6 +158,15 @@ final class PumpStream implements StreamInterface
public function read($length): string
{
if (!\is_int($length)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to StreamInterface::read() is deprecated; guzzlehttp/psr7 3.0 requires int for $length.',
\get_debug_type($length)
);
}
$data = $this->buffer->read($length);
$readLen = strlen($data);
$this->tellPos += $readLen;
@ -154,6 +196,15 @@ final class PumpStream implements StreamInterface
*/
public function getMetadata($key = null)
{
if ($key !== null && !\is_string($key)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to StreamInterface::getMetadata() is deprecated; guzzlehttp/psr7 3.0 requires string|null for $key.',
\get_debug_type($key)
);
}
if (!$key) {
return $this->metadata;
}

View file

@ -40,10 +40,11 @@ class Request implements RequestInterface
string $version = '1.1'
) {
$this->assertMethod($method);
if (!($uri instanceof UriInterface)) {
if (!$uri instanceof UriInterface) {
$uri = new Uri($uri);
}
self::warnOnMethodCasingChange($method);
$this->method = strtoupper($method);
$this->uri = $uri;
$this->setHeaders($headers);
@ -97,6 +98,7 @@ class Request implements RequestInterface
public function withMethod($method): RequestInterface
{
$this->assertMethod($method);
self::warnOnMethodCasingChange($method);
$new = clone $this;
$new->method = strtoupper($method);
@ -110,6 +112,15 @@ class Request implements RequestInterface
public function withUri(UriInterface $uri, $preserveHost = false): RequestInterface
{
if (!\is_bool($preserveHost)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to RequestInterface::withUri() is deprecated; guzzlehttp/psr7 3.0 requires bool for $preserveHost.',
\get_debug_type($preserveHost)
);
}
if ($uri === $this->uri) {
return $this;
}
@ -132,10 +143,14 @@ class Request implements RequestInterface
return;
}
Uri::assertValidHost($host);
if (($port = $this->uri->getPort()) !== null) {
$host .= ':'.$port;
}
$this->assertValue($host);
if (isset($this->headerNames['host'])) {
$header = $this->headerNames['host'];
} else {
@ -156,4 +171,15 @@ class Request implements RequestInterface
throw new InvalidArgumentException('Method must be a non-empty string.');
}
}
private static function warnOnMethodCasingChange(string $method): void
{
if ($method !== strtoupper($method)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing a non-uppercase HTTP method is deprecated; guzzlehttp/psr7 3.0 preserves method casing and will no longer uppercase it. Normalize the method before constructing or modifying requests if uppercase is required.'
);
}
}
}

View file

@ -128,6 +128,24 @@ class Response implements ResponseInterface
public function withStatus($code, $reasonPhrase = ''): ResponseInterface
{
if (!\is_int($code) && \filter_var($code, \FILTER_VALIDATE_INT) !== false) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to ResponseInterface::withStatus() is deprecated; guzzlehttp/psr7 3.0 requires int for $code.',
\get_debug_type($code)
);
}
if (!\is_string($reasonPhrase)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to ResponseInterface::withStatus() is deprecated; guzzlehttp/psr7 3.0 requires string for $reasonPhrase.',
\get_debug_type($reasonPhrase)
);
}
$this->assertStatusCodeIsInteger($code);
$code = (int) $code;
$this->assertStatusCodeRange($code);

25
vendor/guzzlehttp/psr7/src/Rfc3986.php vendored Normal file
View file

@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
namespace GuzzleHttp\Psr7;
/**
* @internal
*/
final class Rfc3986
{
/**
* Sub-delims for use in a regex.
*
* @see https://datatracker.ietf.org/doc/html/rfc3986#section-2.2
*/
public const CHAR_SUB_DELIMS = '!\$&\'\(\)\*\+,;=';
/**
* Unreserved characters for use in a regex.
*
* @see https://datatracker.ietf.org/doc/html/rfc3986#section-2.3
*/
public const CHAR_UNRESERVED = 'a-zA-Z0-9_\-\.~';
}

View file

@ -20,4 +20,87 @@ final class Rfc7230
*/
public const HEADER_REGEX = "(^([^()<>@,;:\\\"/[\]?={}\x01-\x20\x7F]++):[ \t]*+((?:[ \t]*+[\x21-\x7E\x80-\xFF]++)*+)[ \t]*+\r?\n)m";
public const HEADER_FOLD_REGEX = "(\r?\n[ \t]++)";
/**
* @return array{0: string, 1: int|null}|null
*/
public static function parseHostHeader(string $authority): ?array
{
if ($authority === '') {
return null;
}
$host = $authority;
$port = null;
if ($authority[0] === '[') {
$closingBracket = strpos($authority, ']');
if ($closingBracket === false) {
return null;
}
$host = substr($authority, 0, $closingBracket + 1);
$remainder = substr($authority, $closingBracket + 1);
if ($remainder !== '') {
if ($remainder[0] !== ':') {
return null;
}
$port = self::parseAuthorityPort(substr($remainder, 1));
if ($port === null) {
return null;
}
}
} elseif (false !== ($colon = strpos($authority, ':'))) {
$host = substr($authority, 0, $colon);
$port = self::parseAuthorityPort(substr($authority, $colon + 1));
if ($port === null) {
return null;
}
}
if ($host === '' || !self::isValidHostHeaderHost($host)) {
return null;
}
return [$host, $port];
}
private static function isValidHostHeaderHost(string $host): bool
{
if (preg_match('/[\x00-\x20\x7F\/\?#@\\\\]/', $host)) {
return false;
}
if (strpos($host, '[') !== false || strpos($host, ']') !== false) {
if ($host[0] !== '[' || substr($host, -1) !== ']') {
return false;
}
$address = substr($host, 1, -1);
return filter_var($address, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV6) !== false
|| preg_match('/^v[0-9a-f]+\.['.Rfc3986::CHAR_UNRESERVED.Rfc3986::CHAR_SUB_DELIMS.':]+$/iD', $address) === 1;
}
return strpos($host, ':') === false;
}
private static function parseAuthorityPort(string $port): ?int
{
if ($port === '' || !ctype_digit($port)) {
return null;
}
$normalized = ltrim($port, '0');
if ($normalized === '') {
return 0;
}
if (strlen($normalized) > 5 || (int) $normalized > 0xFFFF) {
return null;
}
return (int) $normalized;
}
}

View file

@ -165,11 +165,12 @@ class ServerRequest extends Request implements ServerRequestInterface
*/
public static function fromGlobals(): ServerRequestInterface
{
$method = $_SERVER['REQUEST_METHOD'] ?? 'GET';
$headers = getallheaders();
$method = strtoupper(self::getServerParam('REQUEST_METHOD') ?? 'GET');
$headers = self::removeInvalidHostHeader(self::getAllHeaders());
$uri = self::getUriFromGlobals();
$body = new CachingStream(new LazyOpenStream('php://input', 'r+'));
$protocol = isset($_SERVER['SERVER_PROTOCOL']) ? str_replace('HTTP/', '', $_SERVER['SERVER_PROTOCOL']) : '1.1';
$serverProtocol = self::getServerParam('SERVER_PROTOCOL');
$protocol = $serverProtocol !== null ? str_replace('HTTP/', '', $serverProtocol) : '1.1';
$serverRequest = new ServerRequest($method, $uri, $headers, $body, $protocol, $_SERVER);
@ -180,18 +181,63 @@ class ServerRequest extends Request implements ServerRequestInterface
->withUploadedFiles(self::normalizeFiles($_FILES));
}
private static function extractHostAndPortFromAuthority(string $authority): array
/**
* @return array<array-key, string>
*/
private static function getAllHeaders(): array
{
$uri = 'http://'.$authority;
$parts = parse_url($uri);
if (false === $parts) {
return [null, null];
return self::normalizeHeaderValues(getallheaders());
}
/**
* @param array<array-key, mixed> $headers
*
* @return array<array-key, string>
*/
private static function normalizeHeaderValues(array $headers): array
{
$normalized = [];
foreach ($headers as $name => $value) {
if (is_scalar($value) || (is_object($value) && method_exists($value, '__toString'))) {
$normalized[$name] = (string) $value;
}
}
$host = $parts['host'] ?? null;
$port = $parts['port'] ?? null;
return $normalized;
}
return [$host, $port];
private static function getServerParam(string $key): ?string
{
return isset($_SERVER[$key]) && is_string($_SERVER[$key]) ? $_SERVER[$key] : null;
}
/**
* @param array<array-key, string> $headers
*
* @return array<array-key, string>
*/
private static function removeInvalidHostHeader(array $headers): array
{
foreach ($headers as $name => $value) {
if (strtolower((string) $name) !== 'host') {
continue;
}
if (Rfc7230::parseHostHeader($value) === null) {
unset($headers[$name]);
}
}
return $headers;
}
/**
* @return array{0: string|null, 1: int|null}
*/
private static function extractHostAndPortFromAuthority(string $authority): array
{
return Rfc7230::parseHostHeader($authority) ?? [null, null];
}
/**
@ -201,11 +247,13 @@ class ServerRequest extends Request implements ServerRequestInterface
{
$uri = new Uri('');
$uri = $uri->withScheme(!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' ? 'https' : 'http');
$https = self::getServerParam('HTTPS');
$uri = $uri->withScheme(!empty($https) && $https !== 'off' ? 'https' : 'http');
$hasPort = false;
if (isset($_SERVER['HTTP_HOST'])) {
[$host, $port] = self::extractHostAndPortFromAuthority($_SERVER['HTTP_HOST']);
$authority = self::getServerParam('HTTP_HOST');
if ($authority !== null) {
[$host, $port] = self::extractHostAndPortFromAuthority($authority);
if ($host !== null) {
$uri = $uri->withHost($host);
}
@ -214,19 +262,21 @@ class ServerRequest extends Request implements ServerRequestInterface
$hasPort = true;
$uri = $uri->withPort($port);
}
} elseif (isset($_SERVER['SERVER_NAME'])) {
$uri = $uri->withHost($_SERVER['SERVER_NAME']);
} elseif (isset($_SERVER['SERVER_ADDR'])) {
$uri = $uri->withHost($_SERVER['SERVER_ADDR']);
} elseif (($serverName = self::getServerParam('SERVER_NAME')) !== null) {
$uri = $uri->withHost($serverName);
} elseif (($serverAddr = self::getServerParam('SERVER_ADDR')) !== null) {
$uri = $uri->withHost($serverAddr);
}
if (!$hasPort && isset($_SERVER['SERVER_PORT'])) {
$uri = $uri->withPort($_SERVER['SERVER_PORT']);
$serverPort = self::getServerParam('SERVER_PORT');
if (!$hasPort && $serverPort !== null && preg_match('/^[+-]?\d+$/', $serverPort) === 1) {
$uri = $uri->withPort((int) $serverPort);
}
$hasQuery = false;
if (isset($_SERVER['REQUEST_URI'])) {
$requestUriParts = explode('?', $_SERVER['REQUEST_URI'], 2);
$requestUri = self::getServerParam('REQUEST_URI');
if ($requestUri !== null) {
$requestUriParts = explode('?', $requestUri, 2);
$uri = $uri->withPath($requestUriParts[0]);
if (isset($requestUriParts[1])) {
$hasQuery = true;
@ -234,8 +284,9 @@ class ServerRequest extends Request implements ServerRequestInterface
}
}
if (!$hasQuery && isset($_SERVER['QUERY_STRING'])) {
$uri = $uri->withQuery($_SERVER['QUERY_STRING']);
$queryString = self::getServerParam('QUERY_STRING');
if (!$hasQuery && $queryString !== null) {
$uri = $uri->withQuery($queryString);
}
return $uri;
@ -253,6 +304,37 @@ class ServerRequest extends Request implements ServerRequestInterface
public function withUploadedFiles(array $uploadedFiles): ServerRequestInterface
{
$invalidUploadedFileFound = false;
$invalidUploadedFile = null;
$stack = [$uploadedFiles];
while ($stack !== []) {
foreach (\array_pop($stack) as $uploadedFile) {
if ($uploadedFile instanceof UploadedFileInterface) {
continue;
}
if (\is_array($uploadedFile)) {
$stack[] = $uploadedFile;
continue;
}
$invalidUploadedFileFound = true;
$invalidUploadedFile = $uploadedFile;
break 2;
}
}
if ($invalidUploadedFileFound) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s inside ServerRequestInterface::withUploadedFiles() is deprecated; guzzlehttp/psr7 3.0 requires an UploadedFileInterface[] tree.',
\get_debug_type($invalidUploadedFile)
);
}
$new = clone $this;
$new->uploadedFiles = $uploadedFiles;
@ -295,6 +377,15 @@ class ServerRequest extends Request implements ServerRequestInterface
public function withParsedBody($data): ServerRequestInterface
{
if ($data !== null && !\is_array($data) && !\is_object($data)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to ServerRequestInterface::withParsedBody() is deprecated; guzzlehttp/psr7 3.0 requires array|object|null.',
\get_debug_type($data)
);
}
$new = clone $this;
$new->parsedBody = $data;
@ -311,6 +402,15 @@ class ServerRequest extends Request implements ServerRequestInterface
*/
public function getAttribute($attribute, $default = null)
{
if (!\is_string($attribute)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to ServerRequestInterface::getAttribute() is deprecated; guzzlehttp/psr7 3.0 requires string for $attribute.',
\get_debug_type($attribute)
);
}
if (false === array_key_exists($attribute, $this->attributes)) {
return $default;
}
@ -320,6 +420,15 @@ class ServerRequest extends Request implements ServerRequestInterface
public function withAttribute($attribute, $value): ServerRequestInterface
{
if (!\is_string($attribute)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to ServerRequestInterface::withAttribute() is deprecated; guzzlehttp/psr7 3.0 requires string for $attribute.',
\get_debug_type($attribute)
);
}
$new = clone $this;
$new->attributes[$attribute] = $value;
@ -328,6 +437,15 @@ class ServerRequest extends Request implements ServerRequestInterface
public function withoutAttribute($attribute): ServerRequestInterface
{
if (!\is_string($attribute)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to ServerRequestInterface::withoutAttribute() is deprecated; guzzlehttp/psr7 3.0 requires string for $attribute.',
\get_debug_type($attribute)
);
}
if (false === array_key_exists($attribute, $this->attributes)) {
return $this;
}

View file

@ -63,7 +63,7 @@ class Stream implements StreamInterface
$this->seekable = $meta['seekable'];
$this->readable = (bool) preg_match(self::READABLE_MODES, $meta['mode']);
$this->writable = (bool) preg_match(self::WRITABLE_MODES, $meta['mode']);
$this->uri = $this->getMetadata('uri');
$this->uri = $meta['uri'] ?? null;
}
/**
@ -200,6 +200,24 @@ class Stream implements StreamInterface
public function seek($offset, $whence = SEEK_SET): void
{
if (!\is_int($offset)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to StreamInterface::seek() is deprecated; guzzlehttp/psr7 3.0 requires int for $offset.',
\get_debug_type($offset)
);
}
if (!\is_int($whence)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to StreamInterface::seek() is deprecated; guzzlehttp/psr7 3.0 requires int for $whence.',
\get_debug_type($whence)
);
}
$whence = (int) $whence;
if (!isset($this->stream)) {
@ -216,6 +234,15 @@ class Stream implements StreamInterface
public function read($length): string
{
if (!\is_int($length)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to StreamInterface::read() is deprecated; guzzlehttp/psr7 3.0 requires int for $length.',
\get_debug_type($length)
);
}
if (!isset($this->stream)) {
throw new \RuntimeException('Stream is detached');
}
@ -245,6 +272,15 @@ class Stream implements StreamInterface
public function write($string): int
{
if (!\is_string($string)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to StreamInterface::write() is deprecated; guzzlehttp/psr7 3.0 requires string for $string.',
\get_debug_type($string)
);
}
if (!isset($this->stream)) {
throw new \RuntimeException('Stream is detached');
}
@ -268,6 +304,15 @@ class Stream implements StreamInterface
*/
public function getMetadata($key = null)
{
if ($key !== null && !\is_string($key)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to StreamInterface::getMetadata() is deprecated; guzzlehttp/psr7 3.0 requires string|null for $key.',
\get_debug_type($key)
);
}
if (!isset($this->stream)) {
return $key ? null : [];
} elseif (!$key) {

View file

@ -86,6 +86,15 @@ trait StreamDecoratorTrait
*/
public function getMetadata($key = null)
{
if ($key !== null && !\is_string($key)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to StreamInterface::getMetadata() is deprecated; guzzlehttp/psr7 3.0 requires string|null for $key.',
\get_debug_type($key)
);
}
return $this->stream->getMetadata($key);
}
@ -131,16 +140,52 @@ trait StreamDecoratorTrait
public function seek($offset, $whence = SEEK_SET): void
{
if (!\is_int($offset)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to StreamInterface::seek() is deprecated; guzzlehttp/psr7 3.0 requires int for $offset.',
\get_debug_type($offset)
);
}
if (!\is_int($whence)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to StreamInterface::seek() is deprecated; guzzlehttp/psr7 3.0 requires int for $whence.',
\get_debug_type($whence)
);
}
$this->stream->seek($offset, $whence);
}
public function read($length): string
{
if (!\is_int($length)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to StreamInterface::read() is deprecated; guzzlehttp/psr7 3.0 requires int for $length.',
\get_debug_type($length)
);
}
return $this->stream->read($length);
}
public function write($string): int
{
if (!\is_string($string)) {
\trigger_deprecation(
'guzzlehttp/psr7',
'2.11',
'Passing %s to StreamInterface::write() is deprecated; guzzlehttp/psr7 3.0 requires string for $string.',
\get_debug_type($string)
);
}
return $this->stream->write($string);
}

Some files were not shown because too many files have changed in this diff Show more