mirror of
https://github.com/itflow-org/itflow
synced 2026-08-16 12:35:11 +00:00
Update imapengine dependancies too
This commit is contained in:
137
libs/vendor/guzzlehttp/psr7/src/Request.php
vendored
137
libs/vendor/guzzlehttp/psr7/src/Request.php
vendored
@@ -16,14 +16,11 @@ class Request implements RequestInterface
|
||||
{
|
||||
use MessageTrait;
|
||||
|
||||
/** @var string */
|
||||
private $method;
|
||||
private string $method;
|
||||
|
||||
/** @var string|null */
|
||||
private $requestTarget;
|
||||
private ?string $requestTarget = null;
|
||||
|
||||
/** @var UriInterface */
|
||||
private $uri;
|
||||
private UriInterface $uri;
|
||||
|
||||
/**
|
||||
* @param string $method HTTP method
|
||||
@@ -45,9 +42,9 @@ class Request implements RequestInterface
|
||||
if (!$uri instanceof UriInterface) {
|
||||
$uri = new Uri($uri);
|
||||
}
|
||||
self::getRequestTargetFromUri($uri);
|
||||
|
||||
self::warnOnMethodCasingChange($method);
|
||||
$this->method = Utils::asciiToUpper($method);
|
||||
$this->method = $method;
|
||||
$this->uri = $uri;
|
||||
$this->setHeaders($headers);
|
||||
$this->protocol = $version;
|
||||
@@ -67,30 +64,12 @@ class Request implements RequestInterface
|
||||
return $this->requestTarget;
|
||||
}
|
||||
|
||||
$target = $this->uri->getPath();
|
||||
if ($target === '') {
|
||||
$target = '/';
|
||||
}
|
||||
if ($this->uri->getQuery() != '') {
|
||||
$target .= '?'.$this->uri->getQuery();
|
||||
}
|
||||
|
||||
return $target;
|
||||
return self::getRequestTargetFromUri($this->uri);
|
||||
}
|
||||
|
||||
public function withRequestTarget($requestTarget): RequestInterface
|
||||
public function withRequestTarget(string $requestTarget): RequestInterface
|
||||
{
|
||||
$hasWhitespace = preg_match('#\s#', $requestTarget);
|
||||
|
||||
if ($hasWhitespace === false) {
|
||||
throw new \RuntimeException('Unable to validate request target: '.preg_last_error_msg());
|
||||
}
|
||||
|
||||
if ($hasWhitespace === 1) {
|
||||
throw new InvalidArgumentException(
|
||||
'Invalid request target provided; cannot contain whitespace'
|
||||
);
|
||||
}
|
||||
self::assertRequestTarget($requestTarget);
|
||||
|
||||
$new = clone $this;
|
||||
$new->requestTarget = $requestTarget;
|
||||
@@ -103,12 +82,11 @@ class Request implements RequestInterface
|
||||
return $this->method;
|
||||
}
|
||||
|
||||
public function withMethod($method): RequestInterface
|
||||
public function withMethod(string $method): RequestInterface
|
||||
{
|
||||
$this->assertMethod($method);
|
||||
self::warnOnMethodCasingChange($method);
|
||||
$new = clone $this;
|
||||
$new->method = Utils::asciiToUpper($method);
|
||||
$new->method = $method;
|
||||
|
||||
return $new;
|
||||
}
|
||||
@@ -118,26 +96,30 @@ class Request implements RequestInterface
|
||||
return $this->uri;
|
||||
}
|
||||
|
||||
public function withUri(UriInterface $uri, $preserveHost = false): RequestInterface
|
||||
public function withUri(UriInterface $uri, bool $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)
|
||||
);
|
||||
$sameUri = $uri === $this->uri;
|
||||
|
||||
if (!$sameUri && $this->requestTarget === null) {
|
||||
self::getRequestTargetFromUri($uri);
|
||||
}
|
||||
|
||||
if ($uri === $this->uri) {
|
||||
$currentHost = $this->getHeaderLine('Host');
|
||||
$host = null;
|
||||
|
||||
if (!$preserveHost || $currentHost === '') {
|
||||
$host = $this->getHostFromUri($uri);
|
||||
}
|
||||
|
||||
if ($sameUri && ($host === null || $currentHost === $host)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$new = clone $this;
|
||||
$new->uri = $uri;
|
||||
|
||||
if (!$preserveHost || !isset($this->headerNames['host'])) {
|
||||
$new->updateHostFromUri();
|
||||
if ($host !== null) {
|
||||
$new->setHostHeader($host);
|
||||
}
|
||||
|
||||
return $new;
|
||||
@@ -145,20 +127,36 @@ class Request implements RequestInterface
|
||||
|
||||
private function updateHostFromUri(): void
|
||||
{
|
||||
$host = $this->uri->getHost();
|
||||
$host = $this->getHostFromUri($this->uri);
|
||||
|
||||
if ($host == '') {
|
||||
if ($host === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->setHostHeader($host);
|
||||
}
|
||||
|
||||
private function getHostFromUri(UriInterface $uri): ?string
|
||||
{
|
||||
$host = $uri->getHost();
|
||||
|
||||
if ($host === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
Uri::assertValidHost($host);
|
||||
|
||||
if (($port = $this->uri->getPort()) !== null) {
|
||||
if (($port = $uri->getPort()) !== null) {
|
||||
$host .= ':'.$port;
|
||||
}
|
||||
|
||||
$this->assertValue($host);
|
||||
|
||||
return $host;
|
||||
}
|
||||
|
||||
private function setHostHeader(string $host): void
|
||||
{
|
||||
if (isset($this->headerNames['host'])) {
|
||||
$header = $this->headerNames['host'];
|
||||
} else {
|
||||
@@ -166,30 +164,47 @@ class Request implements RequestInterface
|
||||
$this->headerNames['host'] = 'Host';
|
||||
}
|
||||
// Ensure Host is the first header.
|
||||
// See: https://datatracker.ietf.org/doc/html/rfc7230#section-5.4
|
||||
// See: https://datatracker.ietf.org/doc/html/rfc9110#section-7.2
|
||||
$this->headers = [$header => [$host]] + $this->headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $method
|
||||
*/
|
||||
private function assertMethod($method): void
|
||||
private function assertMethod(string $method): void
|
||||
{
|
||||
if (!is_string($method) || $method === '') {
|
||||
throw new InvalidArgumentException('Method must be a non-empty string.');
|
||||
if (!Rfc9110::isToken($method)) {
|
||||
throw new InvalidArgumentException('Method must be a valid HTTP token.');
|
||||
}
|
||||
|
||||
$this->assertNoLineSeparators($method, 'Method');
|
||||
}
|
||||
|
||||
private static function warnOnMethodCasingChange(string $method): void
|
||||
private static function getRequestTargetFromUri(UriInterface $uri): string
|
||||
{
|
||||
if ($method !== Utils::asciiToUpper($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.'
|
||||
$target = self::normalizePathForOriginForm($uri->getPath());
|
||||
if ($target === '') {
|
||||
$target = '/';
|
||||
}
|
||||
if ($uri->getQuery() != '') {
|
||||
$target .= '?'.$uri->getQuery();
|
||||
}
|
||||
|
||||
self::assertRequestTarget($target);
|
||||
|
||||
return $target;
|
||||
}
|
||||
|
||||
private static function assertRequestTarget(string $requestTarget): void
|
||||
{
|
||||
if (!Rfc9112::isValidRequestTarget($requestTarget)) {
|
||||
throw new InvalidArgumentException(
|
||||
'Invalid request target provided; cannot be empty or contain whitespace or control characters'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private static function normalizePathForOriginForm(string $path): string
|
||||
{
|
||||
if (str_starts_with($path, '//')) {
|
||||
return '/'.ltrim($path, '/');
|
||||
}
|
||||
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user