Phase 0: Fundament für Inhaus
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s
- Laravel 13 mit Filament 5 (Admin), Inertia 3 + Vue 3 + Vuetify 4 (Material 3) - Anmeldung über Fortify (Login, Passwort vergessen/ändern), keine Selbstregistrierung - Profil mit Profilbild (WebP in festen Größen), Personenseiten, Header mit Avatar-Menü - Material-3-Farbschema aus der Primärfarbe, hell/dunkel/System pro Person - Basis-Branding (Portalname, Logo, Primärfarbe) im Admin unter „Erscheinungsbild“ - Benutzerverwaltung im Admin, Zugang vorläufig über is_admin - vendor/ (ohne Dev-Pakete) und Frontend-Build mitversioniert, Dev-Pakete in vendor-dev/ - PHPUnit-Tests gegen MySQL/MariaDB, Forgejo-CI-Matrix, Docker-Entwicklungsumgebung - VERSION, CHANGELOG.md und CONTRIBUTING.md mit Release-Ablauf Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
7197eaebf2
commit
9c0f8de791
15771 changed files with 1564103 additions and 5 deletions
23
vendor/guzzlehttp/guzzle/src/Handler/Clock.php
vendored
Normal file
23
vendor/guzzlehttp/guzzle/src/Handler/Clock.php
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GuzzleHttp\Handler;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class Clock
|
||||
{
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current monotonic clock reading in seconds.
|
||||
*/
|
||||
public static function now(): float
|
||||
{
|
||||
return \hrtime(true) / 1e9;
|
||||
}
|
||||
}
|
||||
3152
vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php
vendored
Normal file
3152
vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php
vendored
Normal file
File diff suppressed because it is too large
Load diff
31
vendor/guzzlehttp/guzzle/src/Handler/CurlFactoryInterface.php
vendored
Normal file
31
vendor/guzzlehttp/guzzle/src/Handler/CurlFactoryInterface.php
vendored
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GuzzleHttp\Handler;
|
||||
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
|
||||
interface CurlFactoryInterface
|
||||
{
|
||||
/**
|
||||
* Creates a cURL handle resource.
|
||||
*
|
||||
* Implementations must return an EasyHandle whose public state properties,
|
||||
* including the request and sink, contain values compatible with Guzzle's
|
||||
* cURL handlers.
|
||||
*
|
||||
* @param RequestInterface $request Request
|
||||
* @param array $options Transfer options
|
||||
*
|
||||
* @throws \RuntimeException when an option cannot be applied
|
||||
*/
|
||||
public function create(RequestInterface $request, array $options): EasyHandle;
|
||||
|
||||
/**
|
||||
* Release an easy handle, allowing it to be reused or closed.
|
||||
*
|
||||
* This function must call unset on the easy handle's "handle" property.
|
||||
*/
|
||||
public function release(EasyHandle $easy): void;
|
||||
}
|
||||
162
vendor/guzzlehttp/guzzle/src/Handler/CurlHandler.php
vendored
Normal file
162
vendor/guzzlehttp/guzzle/src/Handler/CurlHandler.php
vendored
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GuzzleHttp\Handler;
|
||||
|
||||
use GuzzleHttp\Exception\InvalidArgumentException;
|
||||
use GuzzleHttp\NonSerializableTrait;
|
||||
use GuzzleHttp\Promise\PromiseInterface;
|
||||
use GuzzleHttp\Psr7\DiagnosticValue;
|
||||
use GuzzleHttp\TransportSharing;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* HTTP handler that uses cURL easy handles as a transport layer.
|
||||
*
|
||||
* When using the CurlHandler, custom curl options can be specified as an
|
||||
* associative array of curl option constants mapping to values in the
|
||||
* **curl** key of the "client" key of the request.
|
||||
*/
|
||||
final class CurlHandler
|
||||
{
|
||||
use NonSerializableTrait;
|
||||
|
||||
private const KNOWN_CONSTRUCTOR_OPTIONS = [
|
||||
'handle_factory' => true,
|
||||
'transport_sharing' => true,
|
||||
];
|
||||
|
||||
private CurlFactoryInterface $factory;
|
||||
|
||||
private bool $ownsFactory;
|
||||
|
||||
private bool $closed = false;
|
||||
|
||||
private ?CurlShareHandleState $shareHandleState;
|
||||
|
||||
/**
|
||||
* Accepts an associative array of options:
|
||||
*
|
||||
* - handle_factory: Optional curl factory used to create cURL handles.
|
||||
* - transport_sharing: Optional transport sharing mode.
|
||||
*
|
||||
* @param array{handle_factory?: ?CurlFactoryInterface, transport_sharing?: mixed} $options Array of options to use with the handler
|
||||
*/
|
||||
public function __construct(array $options = [])
|
||||
{
|
||||
foreach ($options as $name => $_) {
|
||||
if (!isset(self::KNOWN_CONSTRUCTOR_OPTIONS[$name])) {
|
||||
throw new InvalidArgumentException(\sprintf('Invalid CurlHandler constructor option "%s".', DiagnosticValue::escape((string) $name)));
|
||||
}
|
||||
}
|
||||
|
||||
CurlShareHandleState::assertNoRequiredSharingCustomFactoryConflict($options, 'CurlHandler');
|
||||
$transportSharing = $options['transport_sharing'] ?? null;
|
||||
$sharingMode = CurlShareHandleState::normalizeMode($transportSharing, 'transport_sharing');
|
||||
|
||||
if (\array_key_exists('handle_factory', $options) && $options['handle_factory'] !== null) {
|
||||
$this->shareHandleState = null;
|
||||
$this->factory = $options['handle_factory'];
|
||||
$this->ownsFactory = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->shareHandleState = $sharingMode !== TransportSharing::NONE
|
||||
? CurlShareHandleState::fromOption($transportSharing)
|
||||
: null;
|
||||
|
||||
$this->factory = $this->shareHandleState !== null
|
||||
? new CurlFactory(3, $this->shareHandleState->mode, $this->shareHandleState)
|
||||
: new CurlFactory(3);
|
||||
|
||||
$this->ownsFactory = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PromiseInterface<ResponseInterface, mixed>
|
||||
*/
|
||||
public function __invoke(
|
||||
#[\SensitiveParameter]
|
||||
RequestInterface $request,
|
||||
#[\SensitiveParameter]
|
||||
array $options
|
||||
): PromiseInterface {
|
||||
$this->assertOpen();
|
||||
HostValidator::assertRequestHost($request);
|
||||
|
||||
if (isset($options['delay'])) {
|
||||
\usleep((int) ($options['delay'] * 1000));
|
||||
}
|
||||
|
||||
// A Multiplexing::NONE request option holds unconditionally here:
|
||||
// the transfer runs alone during the blocking curl_exec(), and even
|
||||
// under persistent transport sharing an in-use connection cannot be
|
||||
// joined from another multi handle, so it never shares its
|
||||
// connection with a concurrent transfer.
|
||||
$easy = $this->factory->create($request, $options);
|
||||
|
||||
\curl_exec($easy->handle);
|
||||
$easy->errno = \curl_errno($easy->handle);
|
||||
|
||||
return CurlFactory::finish($this, $easy, $this->factory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes native cURL resources owned by this handler.
|
||||
*
|
||||
* After closing, the handler is terminal and must not be reused.
|
||||
*/
|
||||
public function close(): void
|
||||
{
|
||||
$this->doClose(true);
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
try {
|
||||
$this->doClose(false);
|
||||
} catch (\Throwable $e) {
|
||||
// Destructors must not throw.
|
||||
}
|
||||
}
|
||||
|
||||
public function __unserialize(array $data): void
|
||||
{
|
||||
$this->closed = true;
|
||||
|
||||
throw new \LogicException(static::class.' should never be unserialized');
|
||||
}
|
||||
|
||||
private function assertOpen(): void
|
||||
{
|
||||
if ($this->closed) {
|
||||
// Programmer misuse (reusing a closed handler), not a transfer failure;
|
||||
// intentionally a LogicException outside the GuzzleException hierarchy.
|
||||
throw new \BadMethodCallException('Cannot use the cURL handler after it has been closed.');
|
||||
}
|
||||
}
|
||||
|
||||
private function doClose(bool $explicit): void
|
||||
{
|
||||
if ($this->closed) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->closed = true;
|
||||
|
||||
try {
|
||||
if ($this->ownsFactory && $this->factory instanceof CurlFactory) {
|
||||
$this->factory->close();
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
if ($explicit) {
|
||||
throw $e;
|
||||
}
|
||||
} finally {
|
||||
$this->shareHandleState = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
1643
vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php
vendored
Normal file
1643
vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php
vendored
Normal file
File diff suppressed because it is too large
Load diff
276
vendor/guzzlehttp/guzzle/src/Handler/CurlShareHandleState.php
vendored
Normal file
276
vendor/guzzlehttp/guzzle/src/Handler/CurlShareHandleState.php
vendored
Normal file
|
|
@ -0,0 +1,276 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GuzzleHttp\Handler;
|
||||
|
||||
use GuzzleHttp\Exception\InvalidArgumentException;
|
||||
use GuzzleHttp\NonSerializableTrait;
|
||||
use GuzzleHttp\TransportSharing;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class CurlShareHandleState
|
||||
{
|
||||
use NonSerializableTrait;
|
||||
|
||||
/**
|
||||
* @var resource|\CurlShareHandle|\CurlSharePersistentHandle|null
|
||||
*/
|
||||
public $handle;
|
||||
|
||||
public string $mode;
|
||||
|
||||
/**
|
||||
* @param resource|\CurlShareHandle|\CurlSharePersistentHandle|null $handle
|
||||
*/
|
||||
private function __construct(string $mode, $handle)
|
||||
{
|
||||
$this->mode = $mode;
|
||||
$this->handle = $handle;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $sharing
|
||||
*/
|
||||
public static function fromOption($sharing): ?self
|
||||
{
|
||||
if ($sharing instanceof self) {
|
||||
return $sharing;
|
||||
}
|
||||
|
||||
$mode = self::normalizeMode($sharing, 'transport_sharing');
|
||||
if ($mode === TransportSharing::NONE) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($mode === TransportSharing::HANDLER_PREFER) {
|
||||
return self::createHandlerShareOrNull($mode);
|
||||
}
|
||||
|
||||
if ($mode === TransportSharing::HANDLER_REQUIRE) {
|
||||
return self::createHandlerShare($mode);
|
||||
}
|
||||
|
||||
if ($mode === TransportSharing::PERSISTENT_PREFER) {
|
||||
return self::createPersistentShareOrFallback();
|
||||
}
|
||||
|
||||
return self::createPersistentShare($mode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $sharing
|
||||
*/
|
||||
public static function normalizeMode($sharing, string $option): string
|
||||
{
|
||||
if ($sharing instanceof self) {
|
||||
return $sharing->mode;
|
||||
}
|
||||
|
||||
if ($sharing === null || $sharing === TransportSharing::NONE) {
|
||||
return TransportSharing::NONE;
|
||||
}
|
||||
|
||||
if (
|
||||
$sharing === TransportSharing::HANDLER_PREFER
|
||||
|| $sharing === TransportSharing::HANDLER_REQUIRE
|
||||
|| $sharing === TransportSharing::PERSISTENT_PREFER
|
||||
|| $sharing === TransportSharing::PERSISTENT_REQUIRE
|
||||
) {
|
||||
return $sharing;
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException(\sprintf(
|
||||
'The "%s" option must be null or a GuzzleHttp\\TransportSharing::* constant; received %s.',
|
||||
$option,
|
||||
\get_debug_type($sharing)
|
||||
));
|
||||
}
|
||||
|
||||
public static function assertNoRequiredSharingCustomFactoryConflict(array $options, string $handlerName): void
|
||||
{
|
||||
if (!\array_key_exists('handle_factory', $options) || $options['handle_factory'] === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$mode = self::normalizeMode($options['transport_sharing'] ?? null, 'transport_sharing');
|
||||
if (!\in_array($mode, [TransportSharing::HANDLER_REQUIRE, TransportSharing::PERSISTENT_REQUIRE], true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException(\sprintf(
|
||||
'The "transport_sharing" %s option cannot require sharing with a custom "handle_factory" because Guzzle cannot ensure that the custom factory applies CURLOPT_SHARE.',
|
||||
$handlerName
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether cURL can share both the DNS and SSL session cache state that
|
||||
* required handler-lifetime sharing needs, checked without configuring a
|
||||
* share handle so default handler selection can fall back to the stream
|
||||
* handler instead.
|
||||
*/
|
||||
public static function supportsHandlerRequireShare(): bool
|
||||
{
|
||||
return CurlVersion::supportsHandlerSharing()
|
||||
&& CurlVersion::supportsSslSessionSharing()
|
||||
&& \function_exists('curl_share_init')
|
||||
&& \function_exists('curl_share_setopt')
|
||||
&& \defined('CURLOPT_SHARE')
|
||||
&& \defined('CURLSHOPT_SHARE')
|
||||
&& \defined('CURL_LOCK_DATA_DNS')
|
||||
&& \defined('CURL_LOCK_DATA_SSL_SESSION');
|
||||
}
|
||||
|
||||
private static function createHandlerShareOrNull(string $mode): ?self
|
||||
{
|
||||
try {
|
||||
return self::createHandlerShare($mode);
|
||||
} catch (\Throwable $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static function createHandlerShare(string $mode): self
|
||||
{
|
||||
if (!\function_exists('curl_share_init') || !\function_exists('curl_share_setopt')) {
|
||||
throw new InvalidArgumentException('The "transport_sharing" option requires cURL share support.');
|
||||
}
|
||||
|
||||
self::requireCurlConstant('CURLOPT_SHARE');
|
||||
$shareOption = self::requireCurlConstant('CURLSHOPT_SHARE');
|
||||
$locks = self::handlerLocks($mode);
|
||||
$handle = curl_share_init();
|
||||
|
||||
try {
|
||||
foreach ($locks as $lock) {
|
||||
try {
|
||||
$success = curl_share_setopt($handle, $shareOption, $lock);
|
||||
} catch (\Throwable $e) {
|
||||
throw new InvalidArgumentException('Unable to configure cURL share handle: '.$e->getMessage(), 0, $e);
|
||||
}
|
||||
|
||||
if (!$success) {
|
||||
throw new InvalidArgumentException(\sprintf('Unable to configure cURL share handle with lock data %d.', $lock));
|
||||
}
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
self::closeHandlerShareHandleOnPhp7($handle);
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return new self($mode, $handle);
|
||||
}
|
||||
|
||||
private static function createPersistentShareOrFallback(): ?self
|
||||
{
|
||||
if (self::supportsPersistentShare()) {
|
||||
try {
|
||||
return self::createPersistentShare(TransportSharing::PERSISTENT_PREFER);
|
||||
} catch (\Throwable $e) {
|
||||
// Fall back to handler-lifetime best effort below.
|
||||
}
|
||||
}
|
||||
|
||||
return self::createHandlerShareOrNull(TransportSharing::HANDLER_PREFER);
|
||||
}
|
||||
|
||||
private static function createPersistentShare(string $mode): self
|
||||
{
|
||||
CurlVersion::ensureConnectionSharingSupported();
|
||||
CurlVersion::ensureSslSessionSharingSupported();
|
||||
|
||||
if (!self::supportsPersistentShare()) {
|
||||
throw new InvalidArgumentException('The "transport_sharing" option requires persistent cURL share handle support.');
|
||||
}
|
||||
|
||||
self::requireCurlConstant('CURLOPT_SHARE');
|
||||
|
||||
try {
|
||||
$handle = curl_share_init_persistent(self::persistentLocks());
|
||||
} catch (\Throwable $e) {
|
||||
throw new InvalidArgumentException(
|
||||
'Unable to create persistent cURL share handle: '.$e->getMessage(),
|
||||
0,
|
||||
$e
|
||||
);
|
||||
}
|
||||
|
||||
return new self($mode, $handle);
|
||||
}
|
||||
|
||||
private static function supportsPersistentShare(): bool
|
||||
{
|
||||
return CurlVersion::supportsConnectionSharing()
|
||||
&& CurlVersion::supportsSslSessionSharing()
|
||||
&& \function_exists('curl_share_init_persistent')
|
||||
&& \class_exists('CurlSharePersistentHandle')
|
||||
&& \defined('CURL_LOCK_DATA_DNS')
|
||||
&& \defined('CURL_LOCK_DATA_CONNECT')
|
||||
&& \defined('CURL_LOCK_DATA_SSL_SESSION');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int[]
|
||||
*/
|
||||
private static function handlerLocks(string $mode): array
|
||||
{
|
||||
CurlVersion::ensureHandlerSharingSupported();
|
||||
|
||||
if ($mode === TransportSharing::HANDLER_REQUIRE) {
|
||||
CurlVersion::ensureSslSessionSharingSupported();
|
||||
}
|
||||
|
||||
$locks = [
|
||||
self::requireCurlConstant('CURL_LOCK_DATA_DNS'),
|
||||
];
|
||||
|
||||
if (CurlVersion::supportsSslSessionSharing()) {
|
||||
$locks[] = self::requireCurlConstant('CURL_LOCK_DATA_SSL_SESSION');
|
||||
}
|
||||
|
||||
return $locks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int[]
|
||||
*/
|
||||
private static function persistentLocks(): array
|
||||
{
|
||||
return [
|
||||
self::requireCurlConstant('CURL_LOCK_DATA_DNS'),
|
||||
self::requireCurlConstant('CURL_LOCK_DATA_CONNECT'),
|
||||
self::requireCurlConstant('CURL_LOCK_DATA_SSL_SESSION'),
|
||||
];
|
||||
}
|
||||
|
||||
private static function requireCurlConstant(string $constant): int
|
||||
{
|
||||
if (!\defined($constant)) {
|
||||
throw new InvalidArgumentException(\sprintf(
|
||||
'The "transport_sharing" option requires %s, but it is not available in the installed PHP cURL extension.',
|
||||
$constant
|
||||
));
|
||||
}
|
||||
|
||||
$value = \constant($constant);
|
||||
if (!\is_int($value)) {
|
||||
throw new InvalidArgumentException(\sprintf('The cURL constant %s must resolve to an integer.', $constant));
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource|\CurlShareHandle $handle
|
||||
*/
|
||||
private static function closeHandlerShareHandleOnPhp7($handle): void
|
||||
{
|
||||
if (\PHP_VERSION_ID < 80000 && \is_resource($handle)) {
|
||||
curl_share_close($handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
407
vendor/guzzlehttp/guzzle/src/Handler/CurlVersion.php
vendored
Normal file
407
vendor/guzzlehttp/guzzle/src/Handler/CurlVersion.php
vendored
Normal file
|
|
@ -0,0 +1,407 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GuzzleHttp\Handler;
|
||||
|
||||
use GuzzleHttp\Exception\ConnectException;
|
||||
use GuzzleHttp\Exception\InvalidArgumentException;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class CurlVersion
|
||||
{
|
||||
private const MIN_VERSION = '7.34.0';
|
||||
|
||||
private const TLS_13_VERSION = '7.52.0';
|
||||
|
||||
// CURLOPT_PIPEWAIT exists since libcurl 7.43.0, and multi handles have
|
||||
// multiplexed by default since 7.62.0 - but a 7.65.0-7.65.1 regression
|
||||
// dropped that default, which 7.65.2 restored, so 7.65.2 is the floor at
|
||||
// which PIPEWAIT is reliably effective.
|
||||
private const MULTIPLEX_VERSION = '7.65.2';
|
||||
|
||||
// libcurl's connection matcher refuses to hand a transfer wanting
|
||||
// HTTP/1.x a pooled connection that already negotiated HTTP/2 or newer
|
||||
// from 7.77.0: ConnectionExists() in lib/url.c gained the check between
|
||||
// the 7.76.0 and 7.77.0 releases. The HTTP/2 branch of the check
|
||||
// regressed to a debug log in 8.11.0 (curl commit 433d730) and was
|
||||
// restored in 8.13.0 via the negotiation mask (curl commit db72b8d), so
|
||||
// 8.11.0 through 8.12.1 are vulnerable again.
|
||||
private const HTTP_VERSION_REUSE_MATCH_VERSION = '7.77.0';
|
||||
|
||||
private const HTTP_VERSION_REUSE_MATCH_REGRESSION = '8.11.0';
|
||||
|
||||
private const HTTP_VERSION_REUSE_MATCH_RESTORED = '8.13.0';
|
||||
|
||||
// CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE restricts the ALPN offer to h2 only
|
||||
// since libcurl 8.10.0, and connection reuse matching stopped handing
|
||||
// lower-version connections to prior-knowledge transfers in 8.14.0; below
|
||||
// that, a required HTTP/2 request could silently be sent over a reused
|
||||
// HTTP/1.1 connection.
|
||||
private const REQUIRED_HTTP2_MULTIPLEX_VERSION = '8.14.0';
|
||||
|
||||
// Version-aware connection reuse matching arrived in libcurl 8.13.0 with
|
||||
// an HTTP/3-only mask for CURL_HTTP_VERSION_3ONLY transfers; below that,
|
||||
// a required HTTP/3 request could silently ride a reused HTTP/2
|
||||
// connection.
|
||||
private const REQUIRED_HTTP3_MULTIPLEX_VERSION = '8.13.0';
|
||||
|
||||
// curl 7.52.0 introduced HTTPS proxy support, advertised by a feature bit
|
||||
// (a build can meet the version yet lack the feature). Earlier libcurl
|
||||
// mishandles an https:// proxy: before 7.50.2 it silently downgrades to a
|
||||
// plaintext HTTP proxy, and 7.50.2 through 7.51 reject it at connect time.
|
||||
// The 7.52.0 TLS rework also shipped verification flaws in exactly this
|
||||
// path (CVE-2017-2629, CVE-2017-7468); the latter affects 7.52.0-7.53.1
|
||||
// and was fixed in 7.54.0, so TLS to a proxy is only trusted from there.
|
||||
private const HTTPS_PROXY_VERSION = '7.54.0';
|
||||
|
||||
// HTTP/3 arrived in libcurl 7.66.0, but CURL_HTTP_VERSION_3ONLY only
|
||||
// exists from 7.88.0; requiring it keeps every HTTP/3-capable runtime
|
||||
// able to pin HTTP/3 with no downgrade.
|
||||
private const HTTP_3_VERSION = '7.88.0';
|
||||
|
||||
private const PROTOCOLS_STR_VERSION = '7.85.0';
|
||||
|
||||
private const HANDLER_SHARING_VERSION = '7.35.0';
|
||||
|
||||
private const SSL_SESSION_SHARING_VERSION = '8.6.0';
|
||||
|
||||
private const CONNECTION_SHARING_VERSION = '8.12.0';
|
||||
|
||||
// curl 7.57.0 added share-handle connection caches through
|
||||
// CURL_LOCK_DATA_CONNECT; older share objects can only hold DNS, TLS
|
||||
// session, and cookie data, never connections. This is libcurl's raw
|
||||
// capability floor for the opaque share safeguards; Guzzle-managed
|
||||
// connection sharing is separately gated by CONNECTION_SHARING_VERSION.
|
||||
private const SHARE_CONNECTION_CACHE_VERSION = '7.57.0';
|
||||
|
||||
// curl 8.22.0 applies the cURL multi connection caps from the transfer's
|
||||
// own multi handle to transfers using a share-owned connection pool, with
|
||||
// safe eviction from such pools, and documents that contract (curl #22266);
|
||||
// from 8.13.0 (df67269) until then, the limit check on share-owned pools
|
||||
// always passed (curl #22265).
|
||||
public const SHARED_POOL_CONNECTION_CAP_VERSION = '8.22.0';
|
||||
|
||||
// curl 7.83.1 added proxy TLS-SRP to the connection-reuse match
|
||||
// (CVE-2022-27782); the proxy client certificate was matched from 7.52.0,
|
||||
// so proxy TLS credentials are trusted from 7.83.1 onwards.
|
||||
private const PROXY_TLS_CREDENTIAL_REUSE_VERSION = '7.83.1';
|
||||
|
||||
// curl 8.19.0 fixed proxy tunnel reuse after credential changes
|
||||
// (CVE-2026-3784), but related proxy credential leak flaws were only
|
||||
// fixed in 8.20.0, so connection reuse is trusted from 8.20.0 onwards.
|
||||
private const PROXY_CREDENTIAL_REUSE_VERSION = '8.20.0';
|
||||
|
||||
// curl 7.69.0 started comparing SOCKS proxy credentials when matching
|
||||
// connections for reuse (curl #4835); older libcurl matches a SOCKS proxy
|
||||
// by type, host, and port only.
|
||||
private const SOCKS_PROXY_CREDENTIAL_REUSE_VERSION = '7.69.0';
|
||||
|
||||
private const PROXY_HEADER_SEPARATION_VERSION = '7.37.0';
|
||||
|
||||
// CURLOPT_SUPPRESS_CONNECT_HEADERS arrived in curl 7.54.0; proxy CONNECT
|
||||
// tunneling is gated on it so the proxy's interim reply can never surface
|
||||
// as a phantom response on any build that can tunnel.
|
||||
private const PROXY_TUNNEL_VERSION = '7.54.0';
|
||||
|
||||
/**
|
||||
* @var array{version: string, features: int}|false|null
|
||||
*/
|
||||
private static $versionInfo;
|
||||
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public static function supportsCurlHandler(): bool
|
||||
{
|
||||
$versionInfo = self::getVersionInfo();
|
||||
|
||||
return \defined('CURL_VERSION_SSL')
|
||||
&& \defined('CURL_SSLVERSION_TLSv1_2')
|
||||
&& \defined('CURLMOPT_MAX_HOST_CONNECTIONS')
|
||||
&& \defined('CURLMOPT_MAX_TOTAL_CONNECTIONS')
|
||||
&& null !== $versionInfo
|
||||
&& version_compare($versionInfo['version'], self::MIN_VERSION, '>=')
|
||||
&& 0 !== (\CURL_VERSION_SSL & $versionInfo['features']);
|
||||
}
|
||||
|
||||
public static function supportsTls13(): bool
|
||||
{
|
||||
$version = self::get();
|
||||
|
||||
return \defined('CURL_SSLVERSION_TLSv1_3')
|
||||
&& null !== $version
|
||||
&& version_compare($version, self::TLS_13_VERSION, '>=');
|
||||
}
|
||||
|
||||
public static function supportsMultiplex(): bool
|
||||
{
|
||||
$version = self::get();
|
||||
|
||||
return \defined('CURLOPT_PIPEWAIT')
|
||||
&& null !== $version
|
||||
&& version_compare($version, self::MULTIPLEX_VERSION, '>=');
|
||||
}
|
||||
|
||||
public static function supportsHttpVersionReuseMatching(): bool
|
||||
{
|
||||
$version = self::get();
|
||||
|
||||
if (null === $version || version_compare($version, self::HTTP_VERSION_REUSE_MATCH_VERSION, '<')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return version_compare($version, self::HTTP_VERSION_REUSE_MATCH_REGRESSION, '<')
|
||||
|| version_compare($version, self::HTTP_VERSION_REUSE_MATCH_RESTORED, '>=');
|
||||
}
|
||||
|
||||
public static function supportsRequiredHttp2Multiplex(): bool
|
||||
{
|
||||
$version = self::get();
|
||||
|
||||
return \defined('CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE')
|
||||
&& null !== $version
|
||||
&& self::supportsHttp2()
|
||||
&& version_compare($version, self::REQUIRED_HTTP2_MULTIPLEX_VERSION, '>=');
|
||||
}
|
||||
|
||||
public static function supportsHttp2(): bool
|
||||
{
|
||||
$versionInfo = self::getVersionInfo();
|
||||
|
||||
// Requiring dependable CURLOPT_PIPEWAIT support keeps waiting from
|
||||
// ever being silently unavailable where HTTP/2 works.
|
||||
return \defined('CURL_VERSION_HTTP2')
|
||||
&& null !== $versionInfo
|
||||
&& self::supportsMultiplex()
|
||||
&& 0 !== (\CURL_VERSION_HTTP2 & $versionInfo['features']);
|
||||
}
|
||||
|
||||
public static function supportsHttp3(): bool
|
||||
{
|
||||
if (!\defined('CURL_VERSION_HTTP3') || !\defined('CURL_HTTP_VERSION_3') || !\defined('CURL_HTTP_VERSION_3ONLY')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$versionInfo = self::getVersionInfo();
|
||||
if (null === $versionInfo || version_compare($versionInfo['version'], self::HTTP_3_VERSION, '<')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return 0 !== ((int) \constant('CURL_VERSION_HTTP3') & $versionInfo['features']);
|
||||
}
|
||||
|
||||
public static function supportsRequiredHttp3Multiplex(): bool
|
||||
{
|
||||
$version = self::get();
|
||||
|
||||
return self::supportsHttp3()
|
||||
&& null !== $version
|
||||
&& version_compare($version, self::REQUIRED_HTTP3_MULTIPLEX_VERSION, '>=');
|
||||
}
|
||||
|
||||
public static function supportsHttpsProxy(): bool
|
||||
{
|
||||
$versionInfo = self::getVersionInfo();
|
||||
|
||||
return \defined('CURL_VERSION_HTTPS_PROXY')
|
||||
&& null !== $versionInfo
|
||||
&& version_compare($versionInfo['version'], self::HTTPS_PROXY_VERSION, '>=')
|
||||
&& 0 !== (\CURL_VERSION_HTTPS_PROXY & $versionInfo['features']);
|
||||
}
|
||||
|
||||
public static function supportsHandlerSharing(): bool
|
||||
{
|
||||
$version = self::get();
|
||||
|
||||
return null !== $version
|
||||
&& version_compare($version, self::HANDLER_SHARING_VERSION, '>=');
|
||||
}
|
||||
|
||||
public static function ensureHandlerSharingSupported(): void
|
||||
{
|
||||
if (!self::supportsHandlerSharing()) {
|
||||
throw new InvalidArgumentException(\sprintf(
|
||||
'The "transport_sharing" option requires libcurl %s or higher for cURL share handles.',
|
||||
self::HANDLER_SHARING_VERSION
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
public static function supportsSslSessionSharing(): bool
|
||||
{
|
||||
$versionInfo = self::getVersionInfo();
|
||||
|
||||
return \defined('CURL_VERSION_SSL')
|
||||
&& null !== $versionInfo
|
||||
&& version_compare($versionInfo['version'], self::SSL_SESSION_SHARING_VERSION, '>=')
|
||||
&& 0 !== (\CURL_VERSION_SSL & $versionInfo['features']);
|
||||
}
|
||||
|
||||
public static function ensureSslSessionSharingSupported(): void
|
||||
{
|
||||
if (!self::supportsSslSessionSharing()) {
|
||||
throw new InvalidArgumentException(\sprintf(
|
||||
'The "transport_sharing" option requires libcurl %s or higher with SSL support for SSL session sharing.',
|
||||
self::SSL_SESSION_SHARING_VERSION
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
public static function supportsConnectionSharing(): bool
|
||||
{
|
||||
$version = self::get();
|
||||
|
||||
return null !== $version
|
||||
&& version_compare($version, self::CONNECTION_SHARING_VERSION, '>=');
|
||||
}
|
||||
|
||||
public static function ensureConnectionSharingSupported(): void
|
||||
{
|
||||
if (!self::supportsConnectionSharing()) {
|
||||
throw new InvalidArgumentException(\sprintf(
|
||||
'The "transport_sharing" option requires libcurl %s or higher for persistent connection sharing.',
|
||||
self::CONNECTION_SHARING_VERSION
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
public static function supportsSharedPoolConnectionCaps(): bool
|
||||
{
|
||||
$version = self::get();
|
||||
|
||||
return null !== $version
|
||||
&& version_compare($version, self::SHARED_POOL_CONNECTION_CAP_VERSION, '>=');
|
||||
}
|
||||
|
||||
public static function supportsShareConnectionCaches(): bool
|
||||
{
|
||||
$version = self::get();
|
||||
|
||||
// An undetectable libcurl version is treated as capable so the
|
||||
// opaque share safeguards fail closed.
|
||||
return null === $version
|
||||
|| version_compare($version, self::SHARE_CONNECTION_CACHE_VERSION, '>=');
|
||||
}
|
||||
|
||||
public static function supportsProxyTlsCredentialAwareConnectionReuse(): bool
|
||||
{
|
||||
$version = self::get();
|
||||
|
||||
return null !== $version
|
||||
&& version_compare($version, self::PROXY_TLS_CREDENTIAL_REUSE_VERSION, '>=');
|
||||
}
|
||||
|
||||
public static function supportsProxyCredentialAwareConnectionReuse(): bool
|
||||
{
|
||||
$version = self::get();
|
||||
|
||||
return null !== $version
|
||||
&& version_compare($version, self::PROXY_CREDENTIAL_REUSE_VERSION, '>=');
|
||||
}
|
||||
|
||||
public static function supportsSocksProxyCredentialAwareConnectionReuse(): bool
|
||||
{
|
||||
$version = self::get();
|
||||
|
||||
return null !== $version
|
||||
&& version_compare($version, self::SOCKS_PROXY_CREDENTIAL_REUSE_VERSION, '>=');
|
||||
}
|
||||
|
||||
public static function supportsProxyHeaderSeparation(): bool
|
||||
{
|
||||
$version = self::get();
|
||||
|
||||
return null !== $version
|
||||
&& version_compare($version, self::PROXY_HEADER_SEPARATION_VERSION, '>=')
|
||||
&& \defined('CURLOPT_PROXYHEADER')
|
||||
&& \defined('CURLOPT_HEADEROPT')
|
||||
&& \defined('CURLHEADER_SEPARATE');
|
||||
}
|
||||
|
||||
public static function supportsProtocolsStr(): bool
|
||||
{
|
||||
$version = self::get();
|
||||
|
||||
return \defined('CURLOPT_PROTOCOLS_STR')
|
||||
&& null !== $version
|
||||
&& version_compare($version, self::PROTOCOLS_STR_VERSION, '>=');
|
||||
}
|
||||
|
||||
public static function supportsProxyTunneling(): bool
|
||||
{
|
||||
$version = self::get();
|
||||
|
||||
return \defined('CURLOPT_SUPPRESS_CONNECT_HEADERS')
|
||||
&& null !== $version
|
||||
&& version_compare($version, self::PROXY_TUNNEL_VERSION, '>=');
|
||||
}
|
||||
|
||||
public static function ensureSupported(
|
||||
#[\SensitiveParameter]
|
||||
RequestInterface $request
|
||||
): void {
|
||||
if (self::supportsCurlHandler()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$version = self::get();
|
||||
|
||||
if (null === $version || version_compare($version, self::MIN_VERSION, '<')) {
|
||||
throw new ConnectException(\sprintf(
|
||||
'cURL %s or higher is required by the cURL handler; %s is installed.',
|
||||
self::MIN_VERSION,
|
||||
$version ?? 'an unknown version'
|
||||
), $request);
|
||||
}
|
||||
|
||||
if (!\defined('CURL_SSLVERSION_TLSv1_2')) {
|
||||
throw new ConnectException(\sprintf(
|
||||
'The PHP cURL extension must be built against cURL %s or higher to use the cURL handler.',
|
||||
self::MIN_VERSION
|
||||
), $request);
|
||||
}
|
||||
|
||||
if (!\defined('CURLMOPT_MAX_HOST_CONNECTIONS') || !\defined('CURLMOPT_MAX_TOTAL_CONNECTIONS')) {
|
||||
throw new ConnectException('The PHP cURL extension must expose CURLMOPT_MAX_HOST_CONNECTIONS and CURLMOPT_MAX_TOTAL_CONNECTIONS to use the cURL handler.', $request);
|
||||
}
|
||||
|
||||
throw new ConnectException('The cURL handler requires libcurl SSL support.', $request);
|
||||
}
|
||||
|
||||
private static function get(): ?string
|
||||
{
|
||||
$versionInfo = self::getVersionInfo();
|
||||
|
||||
return null === $versionInfo ? null : $versionInfo['version'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{version: string, features: int}|null
|
||||
*/
|
||||
private static function getVersionInfo(): ?array
|
||||
{
|
||||
if (null === self::$versionInfo) {
|
||||
if (!\function_exists('curl_version')) {
|
||||
self::$versionInfo = false;
|
||||
} else {
|
||||
$versionInfo = \curl_version();
|
||||
self::$versionInfo = \is_array($versionInfo)
|
||||
&& isset($versionInfo['version'], $versionInfo['features'])
|
||||
&& \is_string($versionInfo['version'])
|
||||
&& \is_int($versionInfo['features'])
|
||||
? [
|
||||
'version' => $versionInfo['version'],
|
||||
'features' => $versionInfo['features'],
|
||||
]
|
||||
: false;
|
||||
}
|
||||
}
|
||||
|
||||
return false === self::$versionInfo ? null : self::$versionInfo;
|
||||
}
|
||||
}
|
||||
114
vendor/guzzlehttp/guzzle/src/Handler/DeadlineSourceStream.php
vendored
Normal file
114
vendor/guzzlehttp/guzzle/src/Handler/DeadlineSourceStream.php
vendored
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GuzzleHttp\Handler;
|
||||
|
||||
use GuzzleHttp\NonSerializableTrait;
|
||||
use GuzzleHttp\Psr7\Exception\TimeoutException;
|
||||
use GuzzleHttp\Psr7\StreamDecoratorTrait;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
|
||||
/**
|
||||
* Decorates the transport stream of a buffered response so every read
|
||||
* observes the wall-clock deadline of the "timeout" request option.
|
||||
*
|
||||
* The transport resource must be in non-blocking mode: PHP's filtered
|
||||
* stream reads (chunked and compressed responses) otherwise block until
|
||||
* the full requested length arrives, so a deadline check between reads
|
||||
* never runs while a server keeps sending small pieces of data. Reads
|
||||
* return whatever bytes are available and poll briefly for more, so the
|
||||
* deadline is checked between packets rather than between buffers. The
|
||||
* wait is a bounded sleep because stream_select() cannot watch a stream
|
||||
* that carries a filter.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
final class DeadlineSourceStream implements StreamInterface
|
||||
{
|
||||
use NonSerializableTrait;
|
||||
use StreamDecoratorTrait;
|
||||
|
||||
private const POLL_INTERVAL = 0.05;
|
||||
|
||||
private StreamInterface $stream;
|
||||
|
||||
private float $deadline;
|
||||
|
||||
private ?float $readTimeout;
|
||||
|
||||
private bool $timedOut = false;
|
||||
|
||||
/**
|
||||
* @param StreamInterface $stream Transport stream in non-blocking mode.
|
||||
* @param float $deadline Deadline based on Clock::now().
|
||||
* @param float|null $readTimeout Optional idle timeout per read, in seconds.
|
||||
*/
|
||||
public function __construct(StreamInterface $stream, float $deadline, ?float $readTimeout)
|
||||
{
|
||||
$this->stream = $stream;
|
||||
$this->deadline = $deadline;
|
||||
$this->readTimeout = $readTimeout;
|
||||
}
|
||||
|
||||
public function read(int $length): string
|
||||
{
|
||||
$idleStart = null;
|
||||
|
||||
while (true) {
|
||||
$remaining = $this->deadline - Clock::now();
|
||||
if ($remaining <= 0) {
|
||||
$this->timedOut = true;
|
||||
|
||||
throw new TimeoutException('Unable to read from stream: timed out');
|
||||
}
|
||||
|
||||
$data = $this->stream->read($length);
|
||||
if ($data !== '') {
|
||||
return $data;
|
||||
}
|
||||
if ($this->stream->eof()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$now = Clock::now();
|
||||
if ($idleStart === null) {
|
||||
$idleStart = $now;
|
||||
}
|
||||
if ($this->readTimeout !== null && $now - $idleStart >= $this->readTimeout) {
|
||||
$this->timedOut = true;
|
||||
|
||||
throw new TimeoutException('Unable to read from stream: timed out');
|
||||
}
|
||||
|
||||
$wait = \min($remaining, self::POLL_INTERVAL);
|
||||
if ($this->readTimeout !== null) {
|
||||
$wait = \min($wait, $this->readTimeout - ($now - $idleStart));
|
||||
}
|
||||
\usleep((int) \ceil($wait * 1e6));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports the deadline timeout through the timed_out metadata: reads on
|
||||
* a decoding layer above this stream surface as a generic read failure,
|
||||
* and its timeout recovery consults this stream's metadata to classify
|
||||
* the failure. The transport itself never reports timed_out while in
|
||||
* non-blocking mode.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getMetadata(?string $key = null)
|
||||
{
|
||||
if ($key === 'timed_out') {
|
||||
return $this->timedOut || $this->stream->getMetadata($key) === true;
|
||||
}
|
||||
|
||||
$metadata = $this->stream->getMetadata($key);
|
||||
if ($key === null && \is_array($metadata) && $this->timedOut) {
|
||||
$metadata['timed_out'] = true;
|
||||
}
|
||||
|
||||
return $metadata;
|
||||
}
|
||||
}
|
||||
261
vendor/guzzlehttp/guzzle/src/Handler/EasyHandle.php
vendored
Normal file
261
vendor/guzzlehttp/guzzle/src/Handler/EasyHandle.php
vendored
Normal file
|
|
@ -0,0 +1,261 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GuzzleHttp\Handler;
|
||||
|
||||
use GuzzleHttp\Exception\InvalidArgumentException;
|
||||
use GuzzleHttp\Exception\ResponseException;
|
||||
use GuzzleHttp\Exception\ResponseTransferException;
|
||||
use GuzzleHttp\NonSerializableTrait;
|
||||
use GuzzleHttp\Psr7\DiagnosticValue;
|
||||
use GuzzleHttp\Psr7\Exception\TimeoutException;
|
||||
use GuzzleHttp\Psr7\HttpFactory;
|
||||
use GuzzleHttp\RequestOptions;
|
||||
use GuzzleHttp\Utils;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Psr\Http\Message\ResponseFactoryInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
|
||||
/**
|
||||
* Represents a cURL easy handle and the data it populates.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
final class EasyHandle
|
||||
{
|
||||
use NonSerializableTrait;
|
||||
|
||||
/**
|
||||
* @var resource|\CurlHandle cURL resource
|
||||
*/
|
||||
public $handle;
|
||||
|
||||
public StreamInterface $sink;
|
||||
|
||||
public RequestInterface $request;
|
||||
|
||||
/**
|
||||
* @var list<string> Received HTTP headers so far
|
||||
*/
|
||||
public array $headers = [];
|
||||
|
||||
/**
|
||||
* @var list<string> Valid trailer lines, retained only when an
|
||||
* on_trailers callback is configured
|
||||
*/
|
||||
public array $trailers = [];
|
||||
|
||||
/**
|
||||
* @var bool Whether this handle was configured with CURLOPT_PIPEWAIT
|
||||
*/
|
||||
public bool $usesPipewait = false;
|
||||
|
||||
/**
|
||||
* @var bool Whether processMessages() settled the deferred promise, which
|
||||
* a rewind retry settles with a still-pending promise
|
||||
*/
|
||||
public bool $deferredSettled = false;
|
||||
|
||||
/**
|
||||
* @var ResponseInterface|null Received response (if any)
|
||||
*/
|
||||
public ?ResponseInterface $response = null;
|
||||
|
||||
/**
|
||||
* @var array Request options
|
||||
*/
|
||||
public array $options = [];
|
||||
|
||||
/**
|
||||
* @var int cURL error number (if any)
|
||||
*/
|
||||
public int $errno = 0;
|
||||
|
||||
/**
|
||||
* @var string|null Effective CURLOPT_PROXY value the handle was created with (if any)
|
||||
*/
|
||||
public ?string $effectiveProxy = null;
|
||||
|
||||
/**
|
||||
* Proxy tunnel or SOCKS proxy section signature for connection-reuse
|
||||
* isolation, or null when the request does not require sectioning.
|
||||
*/
|
||||
public ?string $proxyTunnelSignature = null;
|
||||
|
||||
/**
|
||||
* @var \Throwable|null Exception during on_headers (if any)
|
||||
*/
|
||||
public ?\Throwable $onHeadersException = null;
|
||||
|
||||
/**
|
||||
* @var \Throwable|null Exception during progress callback (if any)
|
||||
*/
|
||||
public ?\Throwable $progressException = null;
|
||||
|
||||
/**
|
||||
* @var bool Whether the progress callback requested abort
|
||||
*/
|
||||
public bool $progressAborted = false;
|
||||
|
||||
/**
|
||||
* @var \Throwable|null Exception during createResponse (if any)
|
||||
*/
|
||||
public ?\Throwable $createResponseException = null;
|
||||
|
||||
/**
|
||||
* @var ResponseException|null Response header failure, if any.
|
||||
*/
|
||||
public ?ResponseException $responseHeaderException = null;
|
||||
|
||||
/**
|
||||
* @var TimeoutException|null Exception during request body read timeout.
|
||||
*/
|
||||
public ?TimeoutException $bodyReadTimeoutException = null;
|
||||
|
||||
/**
|
||||
* @var TimeoutException|null Exception during request body rewind timeout.
|
||||
*/
|
||||
public ?TimeoutException $bodyRewindTimeoutException = null;
|
||||
|
||||
/**
|
||||
* @var \Throwable|null Exception during request body rewind.
|
||||
*/
|
||||
public ?\Throwable $bodyRewindException = null;
|
||||
|
||||
/**
|
||||
* @var \Throwable|null Exception during request body read.
|
||||
*/
|
||||
public ?\Throwable $bodyReadException = null;
|
||||
|
||||
/**
|
||||
* @var TimeoutException|null Exception during response sink write timeout.
|
||||
*/
|
||||
public ?TimeoutException $sinkWriteTimeoutException = null;
|
||||
|
||||
/**
|
||||
* @var \Throwable|null Exception during response sink write.
|
||||
*/
|
||||
public ?\Throwable $sinkWriteException = null;
|
||||
|
||||
/**
|
||||
* @var bool Whether the response sink accepted a different byte count.
|
||||
*/
|
||||
public bool $sinkWriteIncomplete = false;
|
||||
|
||||
/**
|
||||
* @var int Number of response body bytes accepted by the sink.
|
||||
*/
|
||||
public int $responseBodyBytes = 0;
|
||||
|
||||
/**
|
||||
* @var \OverflowException|null Unrepresentable response body size or byte count.
|
||||
*/
|
||||
public ?\OverflowException $responseBodySizeException = null;
|
||||
|
||||
/**
|
||||
* Attach a response to the easy handle based on the received headers.
|
||||
*
|
||||
* @throws \RuntimeException if no headers have been received or the first
|
||||
* header line is invalid.
|
||||
*/
|
||||
public function createResponse(): void
|
||||
{
|
||||
$this->response = null;
|
||||
$this->responseBodyBytes = 0;
|
||||
$this->responseBodySizeException = null;
|
||||
$this->responseHeaderException = null;
|
||||
|
||||
[$ver, $status, $reason, $headers] = HeaderProcessor::parseHeaders($this->headers);
|
||||
|
||||
// Non-101 informational responses precede the final response. Do not
|
||||
// expose them as the response for a transfer that ends before the final
|
||||
// response arrives. 101 switches protocol and is kept as terminal.
|
||||
if ($status < 200 && $status !== 101) {
|
||||
return;
|
||||
}
|
||||
|
||||
$framingFailure = null;
|
||||
try {
|
||||
$declaredLength = HeaderProcessor::validateResponseFraming($this->request->getMethod(), $status, $headers);
|
||||
HeaderProcessor::assertContentLengthWithinPlatformLimit($declaredLength);
|
||||
} catch (\RuntimeException $e) {
|
||||
$framingFailure = $e;
|
||||
}
|
||||
|
||||
$normalizedKeys = Utils::normalizeHeaderKeys($headers);
|
||||
$decodeContent = $this->options['decode_content'] ?? false;
|
||||
if ($framingFailure === null && $decodeContent !== false && isset($normalizedKeys['content-encoding'])) {
|
||||
$headers['x-encoded-content-encoding'] = $headers[$normalizedKeys['content-encoding']];
|
||||
unset($headers[$normalizedKeys['content-encoding']]);
|
||||
$encodedContentLength = HeaderProcessor::removeHeader('Content-Length', $headers);
|
||||
if ($encodedContentLength !== []) {
|
||||
$headers['x-encoded-content-length'] = $encodedContentLength;
|
||||
|
||||
try {
|
||||
$bodyLength = $this->sink->getSize();
|
||||
} catch (\Exception $e) {
|
||||
$bodyLength = null;
|
||||
}
|
||||
if ($bodyLength) {
|
||||
$headers['Content-Length'] = [(string) $bodyLength];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Attach a response to the easy handle with the parsed headers. Any
|
||||
// exception propagates to the caller (CurlFactory), which records it as
|
||||
// the createResponseException — do not catch it here.
|
||||
$responseFactory = self::requireResponseFactory($this->options[RequestOptions::RESPONSE_FACTORY] ?? new HttpFactory());
|
||||
$response = $responseFactory->createResponse($status, $reason ?? '')->withProtocolVersion($ver);
|
||||
foreach ($headers as $name => $value) {
|
||||
$response = $response->withAddedHeader((string) $name, $value);
|
||||
}
|
||||
$this->response = $response->withBody($this->sink);
|
||||
|
||||
if ($framingFailure instanceof \OverflowException) {
|
||||
$this->responseHeaderException = new ResponseException(
|
||||
$framingFailure->getMessage(),
|
||||
$this->request,
|
||||
$this->response,
|
||||
$framingFailure
|
||||
);
|
||||
} elseif ($framingFailure !== null) {
|
||||
$this->responseHeaderException = new ResponseTransferException(
|
||||
$framingFailure->getMessage(),
|
||||
$this->request,
|
||||
$this->response,
|
||||
$framingFailure
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $factory
|
||||
*/
|
||||
private static function requireResponseFactory($factory): ResponseFactoryInterface
|
||||
{
|
||||
if (!$factory instanceof ResponseFactoryInterface) {
|
||||
throw new InvalidArgumentException(\sprintf(
|
||||
'%s must be an instance of %s',
|
||||
RequestOptions::RESPONSE_FACTORY,
|
||||
ResponseFactoryInterface::class
|
||||
));
|
||||
}
|
||||
|
||||
return $factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \BadMethodCallException
|
||||
*/
|
||||
public function __get(string $name): void
|
||||
{
|
||||
$msg = $name === 'handle'
|
||||
? 'The EasyHandle has been released'
|
||||
: \sprintf('Invalid property: %s', DiagnosticValue::escape($name));
|
||||
|
||||
throw new \BadMethodCallException($msg);
|
||||
}
|
||||
}
|
||||
83
vendor/guzzlehttp/guzzle/src/Handler/EncodedBodyStream.php
vendored
Normal file
83
vendor/guzzlehttp/guzzle/src/Handler/EncodedBodyStream.php
vendored
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GuzzleHttp\Handler;
|
||||
|
||||
use GuzzleHttp\NonSerializableTrait;
|
||||
use GuzzleHttp\Psr7\StreamDecoratorTrait;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
|
||||
/**
|
||||
* Tracks encoded response bytes beneath a content-decoding stream.
|
||||
*
|
||||
* Reads are bounded by a positive, representable Content-Length so a decoder
|
||||
* cannot consume bytes beyond the response message boundary.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
final class EncodedBodyStream implements StreamInterface
|
||||
{
|
||||
use NonSerializableTrait;
|
||||
use StreamDecoratorTrait;
|
||||
|
||||
private StreamInterface $stream;
|
||||
|
||||
private ?int $limit;
|
||||
|
||||
private int $bytesRead = 0;
|
||||
|
||||
public function __construct(StreamInterface $stream, string $declaredLength)
|
||||
{
|
||||
$this->stream = $stream;
|
||||
|
||||
$limit = HeaderProcessor::contentLengthToInt($declaredLength);
|
||||
$this->limit = $limit !== null && $limit > 0 ? $limit : null;
|
||||
}
|
||||
|
||||
public function eof(): bool
|
||||
{
|
||||
return ($this->limit !== null && $this->bytesRead >= $this->limit)
|
||||
|| $this->stream->eof();
|
||||
}
|
||||
|
||||
public function isSeekable(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function seek(int $offset, int $whence = \SEEK_SET): void
|
||||
{
|
||||
throw new \RuntimeException('Cannot seek a stream while tracking encoded response bytes');
|
||||
}
|
||||
|
||||
public function read(int $length): string
|
||||
{
|
||||
if ($length < 0) {
|
||||
throw new \RuntimeException('Length parameter cannot be negative');
|
||||
}
|
||||
|
||||
if ($this->limit !== null) {
|
||||
$remaining = $this->limit - $this->bytesRead;
|
||||
if ($remaining === 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$length = \min($length, $remaining);
|
||||
}
|
||||
|
||||
$data = $this->stream->read($length);
|
||||
$this->bytesRead = TransferByteCounter::add(
|
||||
$this->bytesRead,
|
||||
\strlen($data),
|
||||
'Response body exceeds the maximum integer size supported on this platform'
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getBytesRead(): int
|
||||
{
|
||||
return $this->bytesRead;
|
||||
}
|
||||
}
|
||||
248
vendor/guzzlehttp/guzzle/src/Handler/HeaderProcessor.php
vendored
Normal file
248
vendor/guzzlehttp/guzzle/src/Handler/HeaderProcessor.php
vendored
Normal file
|
|
@ -0,0 +1,248 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GuzzleHttp\Handler;
|
||||
|
||||
use GuzzleHttp\Psr7;
|
||||
use GuzzleHttp\Utils;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class HeaderProcessor
|
||||
{
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the HTTP version, status code, reason phrase, and headers.
|
||||
*
|
||||
* @param string[] $headers
|
||||
*
|
||||
* @return array{0:string, 1:int, 2:?string, 3:array}
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public static function parseHeaders(array $headers): array
|
||||
{
|
||||
if ($headers === []) {
|
||||
throw new \RuntimeException('Expected a non-empty array of header data');
|
||||
}
|
||||
|
||||
$headers = self::getLastHeaderBlock(\array_values($headers));
|
||||
|
||||
$statusLine = \array_shift($headers);
|
||||
if ($statusLine === null) {
|
||||
throw new \RuntimeException('Expected a non-empty array of header data');
|
||||
}
|
||||
|
||||
$parts = \explode(' ', $statusLine, 3);
|
||||
$protocol = $parts[0];
|
||||
|
||||
if (!Psr7\Utils::caselessEquals(\substr($protocol, 0, 5), 'HTTP/')) {
|
||||
throw new \RuntimeException('HTTP version missing from header data');
|
||||
}
|
||||
|
||||
$version = \substr($protocol, 5);
|
||||
|
||||
if (!\preg_match('/^\d+(?:\.\d+)?$/D', $version)) {
|
||||
throw new \RuntimeException('HTTP version is invalid');
|
||||
}
|
||||
|
||||
$status = $parts[1] ?? null;
|
||||
|
||||
if ($status === null) {
|
||||
throw new \RuntimeException('HTTP status code missing from header data');
|
||||
}
|
||||
|
||||
if (!\preg_match('/^[1-5]\d{2}$/D', $status)) {
|
||||
throw new \RuntimeException('HTTP status code is invalid');
|
||||
}
|
||||
|
||||
$reason = $parts[2] ?? null;
|
||||
|
||||
if ($reason !== null && !\preg_match('/^[\x09\x20-\x7E\x80-\xFF]*$/D', $reason)) {
|
||||
throw new \RuntimeException('HTTP reason phrase is invalid');
|
||||
}
|
||||
|
||||
foreach ($headers as $header) {
|
||||
if (\strpos($header, ':') === false) {
|
||||
throw new \RuntimeException('HTTP header line is invalid');
|
||||
}
|
||||
}
|
||||
|
||||
return [$version, (int) $status, $reason, Utils::headersFromLines($headers)];
|
||||
}
|
||||
|
||||
public static function isStatusLineCandidate(string $line): bool
|
||||
{
|
||||
return \preg_match('/^HTTP\/[0-9]+(?:\.[0-9]+)? [0-9]{3}(?: [^\r\n]*)?(?:\r\n|\r|\n)?$/iD', $line) === 1;
|
||||
}
|
||||
|
||||
public static function isValidHeaderFieldLine(string $line): bool
|
||||
{
|
||||
$parts = \explode(':', $line, 2);
|
||||
|
||||
if (!isset($parts[1])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!\preg_match('/^[a-zA-Z0-9\'`#$%&*+.^_|~!-]+$/D', $parts[0])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return \preg_match('/^[\x20\x09\x21-\x7E\x80-\xFF]*(?:\r\n|\r|\n)?$/D', \trim($parts[1], " \t")) === 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a normalized decimal Content-Length, or null when absent.
|
||||
*
|
||||
* @param string[] $values
|
||||
*
|
||||
* @throws \RuntimeException when Content-Length is malformed or conflicting.
|
||||
*/
|
||||
public static function parseContentLength(array $values): ?string
|
||||
{
|
||||
$length = null;
|
||||
|
||||
foreach ($values as $value) {
|
||||
foreach (\explode(',', $value) as $part) {
|
||||
$part = \trim($part, " \t");
|
||||
if (\preg_match('/^[0-9]+$/D', $part) !== 1) {
|
||||
throw new \RuntimeException('value is not a non-negative decimal integer');
|
||||
}
|
||||
|
||||
$part = \ltrim($part, '0');
|
||||
$part = $part === '' ? '0' : $part;
|
||||
if ($length !== null && $part !== $length) {
|
||||
throw new \RuntimeException('values conflict');
|
||||
}
|
||||
|
||||
$length = $part;
|
||||
}
|
||||
}
|
||||
|
||||
if ($length === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $length;
|
||||
}
|
||||
|
||||
public static function contentLengthToInt(?string $length): ?int
|
||||
{
|
||||
if ($length === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$max = (string) \PHP_INT_MAX;
|
||||
if (
|
||||
\strlen($length) > \strlen($max)
|
||||
|| (\strlen($length) === \strlen($max) && \strcmp($length, $max) > 0)
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (int) $length;
|
||||
}
|
||||
|
||||
public static function assertContentLengthWithinPlatformLimit(?string $length): void
|
||||
{
|
||||
if ($length === null || self::contentLengthToInt($length) !== null) {
|
||||
return;
|
||||
}
|
||||
|
||||
throw new \OverflowException('Content-Length exceeds the maximum integer size supported on this platform');
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates response framing and returns its normalized Content-Length.
|
||||
* Returns null when absent or when ordinary body framing does not apply.
|
||||
*
|
||||
* @param array<string, string[]> $headers
|
||||
*
|
||||
* @throws \RuntimeException when Content-Length is malformed, conflicting,
|
||||
* or combined with Transfer-Encoding
|
||||
*/
|
||||
public static function validateResponseFraming(
|
||||
string $method,
|
||||
int $status,
|
||||
array $headers
|
||||
): ?string {
|
||||
if (!self::responseCanHaveBody($method, $status)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$normalizedKeys = Utils::normalizeHeaderKeys($headers);
|
||||
$contentLength = self::removeHeader('Content-Length', $headers);
|
||||
|
||||
try {
|
||||
$length = self::parseContentLength($contentLength);
|
||||
} catch (\RuntimeException $e) {
|
||||
throw new \RuntimeException('Invalid Content-Length response header: '.$e->getMessage(), 0, $e);
|
||||
}
|
||||
|
||||
if ($length !== null && isset($normalizedKeys['transfer-encoding'])) {
|
||||
throw new \RuntimeException('A response must not contain both Content-Length and Transfer-Encoding');
|
||||
}
|
||||
|
||||
return $length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes every case-insensitive occurrence of a header and returns all
|
||||
* removed values in their original field order.
|
||||
*
|
||||
* @param array<string, string[]> $headers
|
||||
*
|
||||
* @return string[] Removed values across all header-name casings
|
||||
*/
|
||||
public static function removeHeader(string $name, array &$headers): array
|
||||
{
|
||||
$values = [];
|
||||
|
||||
foreach ($headers as $key => $headerValues) {
|
||||
if (Psr7\Utils::caselessEquals((string) $key, $name)) {
|
||||
\array_push($values, ...$headerValues);
|
||||
unset($headers[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a response uses ordinary body framing. A response to HEAD, a
|
||||
* response with a 1xx, 204, or 304 status code, or a 2xx response to
|
||||
* CONNECT never has a body, whatever its framing headers claim. A 205
|
||||
* remains subject to framing even though its semantics require no content.
|
||||
*/
|
||||
public static function responseCanHaveBody(string $method, int $status): bool
|
||||
{
|
||||
return $method !== 'HEAD'
|
||||
&& !($method === 'CONNECT' && $status >= 200 && $status < 300)
|
||||
&& $status >= 200
|
||||
&& $status !== 204
|
||||
&& $status !== 304;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param non-empty-list<string> $headers
|
||||
*
|
||||
* @return list<string>
|
||||
*/
|
||||
private static function getLastHeaderBlock(array $headers): array
|
||||
{
|
||||
$lastStatusLine = 0;
|
||||
|
||||
foreach ($headers as $index => $line) {
|
||||
if (self::isStatusLineCandidate($line)) {
|
||||
$lastStatusLine = $index;
|
||||
}
|
||||
}
|
||||
|
||||
return \array_slice($headers, $lastStatusLine);
|
||||
}
|
||||
}
|
||||
162
vendor/guzzlehttp/guzzle/src/Handler/HostValidator.php
vendored
Normal file
162
vendor/guzzlehttp/guzzle/src/Handler/HostValidator.php
vendored
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GuzzleHttp\Handler;
|
||||
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use GuzzleHttp\Psr7;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
|
||||
/**
|
||||
* Rejects request hosts that a handler could resolve differently from the host
|
||||
* the request names.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
final class HostValidator
|
||||
{
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a request names one unambiguous network host.
|
||||
*
|
||||
* A handler reparses the URI but sends the Host header as given. The URI
|
||||
* host must therefore be printable ASCII, free of percent escapes, a valid
|
||||
* RFC 3986 host, and not numeric-looking parts followed by trailing dots.
|
||||
* Every Host header value must be printable ASCII.
|
||||
*
|
||||
* @throws RequestException
|
||||
*/
|
||||
public static function assertRequestHost(
|
||||
#[\SensitiveParameter]
|
||||
RequestInterface $request
|
||||
): void {
|
||||
self::assertUriHost($request->getUri()->getHost(), $request);
|
||||
|
||||
foreach ($request->getHeader('Host') as $value) {
|
||||
self::assertPrintableAscii((string) $value, 'The request Host header "%s" must contain only printable ASCII characters, because an intermediary or an origin server can otherwise read it as an authority that differs from the one the request names. An internationalized host name has an A-label form that this rule accepts.', $request);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Only the URI host is reparsed for the connection. A Host header is sent
|
||||
* verbatim and may carry a port, brackets, and an RFC 6874 zone identifier.
|
||||
*
|
||||
* @throws RequestException
|
||||
*/
|
||||
private static function assertUriHost(
|
||||
string $host,
|
||||
#[\SensitiveParameter]
|
||||
RequestInterface $request
|
||||
): void {
|
||||
self::assertPrintableAscii($host, 'The request URI host "%s" must contain only printable ASCII characters, because a handler can otherwise connect to a host that differs from the one the request names. An internationalized host name has an A-label form that this rule accepts.', $request);
|
||||
|
||||
if (\strpos($host, '%') !== false) {
|
||||
throw new RequestException(\sprintf('The request URI host "%s" must not contain a percent escape, because a handler decodes it and can then connect to a host that differs from the one the request names.', self::escape($host)), $request);
|
||||
}
|
||||
|
||||
// GuzzleHttp\Psr7\Uri already enforces this predicate, so it only
|
||||
// rejects invalid third-party UriInterface values.
|
||||
if (!Psr7\Rfc3986::isValidHost($host)) {
|
||||
throw new RequestException(\sprintf('The request URI host "%s" must be a valid RFC 3986 host, because a handler reparses the URI and can then connect to a host that differs from the one the request names.', self::escape($host)), $request);
|
||||
}
|
||||
|
||||
// libcurl 8.21.0 drops a trailing dot from inet_aton-style numeric
|
||||
// hosts before connecting, while other readers treat the input as a
|
||||
// name. Test the shape rather than the range so malformed numeric
|
||||
// values fail closed. rtrim() also covers multiple trailing dots if
|
||||
// libcurl later relaxes its current guard. Plain shorthand stays
|
||||
// accepted. HostIdentity uses a broader grammar for cookie matching.
|
||||
//
|
||||
// @see \GuzzleHttp\HostIdentity::canonicalHost()
|
||||
if (\str_ends_with($host, '.') && self::isNumericIpv4Host(\rtrim($host, '.'))) {
|
||||
throw new RequestException(\sprintf('The request URI host "%s" must not be written as one to four decimal, octal or hexadecimal parts followed by one or more trailing dots, because a handler can read that spelling as an IPv4 address and connect to that address while the rest of the process reads a name.', self::escape($host)), $request);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports whether a host has libcurl's inet_aton-style shape: one to four
|
||||
* decimal, 0-prefixed octal, or 0x-prefixed hexadecimal parts.
|
||||
*
|
||||
* Range and 32-bit overflow checks are deliberately omitted. This may
|
||||
* reject a trailing-dot spelling the transport reads as a name, but avoids
|
||||
* missing one it resolves as an address.
|
||||
*/
|
||||
public static function isNumericIpv4Host(string $host): bool
|
||||
{
|
||||
if ($host === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$parts = \explode('.', $host);
|
||||
|
||||
if (\count($parts) > 4) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($parts as $part) {
|
||||
if (!self::isNumericIpv4Part($part)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static function isNumericIpv4Part(string $part): bool
|
||||
{
|
||||
if ($part === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($part[0] === '0' && isset($part[1]) && ($part[1] === 'x' || $part[1] === 'X')) {
|
||||
return \strlen($part) > 2 && \strspn($part, '0123456789abcdefABCDEF', 2) === \strlen($part) - 2;
|
||||
}
|
||||
|
||||
$digits = $part[0] === '0' ? '01234567' : '0123456789';
|
||||
|
||||
return \strspn($part, $digits) === \strlen($part);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws RequestException
|
||||
*/
|
||||
private static function assertPrintableAscii(
|
||||
string $value,
|
||||
string $message,
|
||||
#[\SensitiveParameter]
|
||||
RequestInterface $request
|
||||
): void {
|
||||
// Match positively so a PCRE failure rejects.
|
||||
if (\preg_match('/\A[\x21-\x7E]*\z/D', $value) !== 1) {
|
||||
throw new RequestException(\sprintf($message, self::escape($value)), $request);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes non-printable bytes as uppercase \xNN for safe diagnostics.
|
||||
*
|
||||
* Psr7\DiagnosticValue is not used because it preserves valid non-ASCII
|
||||
* UTF-8, including invisible characters rejected here.
|
||||
*/
|
||||
private static function escape(string $value): string
|
||||
{
|
||||
$escaped = '';
|
||||
|
||||
for ($offset = 0, $length = \strlen($value); $offset < $length; ++$offset) {
|
||||
$byte = \ord($value[$offset]);
|
||||
if ($byte >= 0x20 && $byte <= 0x7E) {
|
||||
$escaped .= $value[$offset];
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$escaped .= \sprintf('\\x%02X', $byte);
|
||||
}
|
||||
|
||||
return $escaped;
|
||||
}
|
||||
}
|
||||
276
vendor/guzzlehttp/guzzle/src/Handler/MockHandler.php
vendored
Normal file
276
vendor/guzzlehttp/guzzle/src/Handler/MockHandler.php
vendored
Normal file
|
|
@ -0,0 +1,276 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GuzzleHttp\Handler;
|
||||
|
||||
use GuzzleHttp\Exception\InvalidArgumentException;
|
||||
use GuzzleHttp\Exception\ResponseException;
|
||||
use GuzzleHttp\HandlerStack;
|
||||
use GuzzleHttp\NonSerializableTrait;
|
||||
use GuzzleHttp\Promise as P;
|
||||
use GuzzleHttp\Promise\PromiseInterface;
|
||||
use GuzzleHttp\TransferStats;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
|
||||
/**
|
||||
* Handler that returns responses or rejection reasons from a queue.
|
||||
*/
|
||||
final class MockHandler implements \Countable
|
||||
{
|
||||
use NonSerializableTrait;
|
||||
|
||||
/**
|
||||
* @var list<ResponseInterface|\Throwable|PromiseInterface<ResponseInterface, mixed>|callable(RequestInterface, array<array-key, mixed>): (ResponseInterface|\Throwable|PromiseInterface<ResponseInterface, mixed>)>
|
||||
*/
|
||||
private array $queue = [];
|
||||
|
||||
private ?RequestInterface $lastRequest = null;
|
||||
|
||||
/**
|
||||
* @var array<array-key, mixed>
|
||||
*/
|
||||
private array $lastOptions = [];
|
||||
|
||||
/**
|
||||
* @var (callable(ResponseInterface|null): mixed)|null
|
||||
*/
|
||||
private $onFulfilled;
|
||||
|
||||
/**
|
||||
* @var (callable(mixed): mixed)|null
|
||||
*/
|
||||
private $onRejected;
|
||||
|
||||
/**
|
||||
* Creates a new MockHandler that uses the default handler stack list of
|
||||
* middlewares.
|
||||
*
|
||||
* @param array<array-key, ResponseInterface|\Throwable|PromiseInterface<ResponseInterface, mixed>|callable(RequestInterface, array<array-key, mixed>): (ResponseInterface|\Throwable|PromiseInterface<ResponseInterface, mixed>)>|null $queue Array of responses, promises, callables, or throwables.
|
||||
* @param (callable(ResponseInterface|null): mixed)|null $onFulfilled Callback to invoke when the return value is fulfilled.
|
||||
* @param (callable(mixed): mixed)|null $onRejected Callback to invoke when the return value is rejected.
|
||||
*
|
||||
* @return HandlerStack<callable(RequestInterface, array<array-key, mixed>): PromiseInterface<ResponseInterface, mixed>>
|
||||
*/
|
||||
public static function createWithMiddleware(
|
||||
#[\SensitiveParameter]
|
||||
?array $queue = null,
|
||||
?callable $onFulfilled = null,
|
||||
?callable $onRejected = null
|
||||
): HandlerStack {
|
||||
return HandlerStack::create(new self($queue, $onFulfilled, $onRejected));
|
||||
}
|
||||
|
||||
/**
|
||||
* The passed in value must be an array of
|
||||
* {@see ResponseInterface} objects, throwables, callables, or promises.
|
||||
*
|
||||
* @param array<array-key, ResponseInterface|\Throwable|PromiseInterface<ResponseInterface, mixed>|callable(RequestInterface, array<array-key, mixed>): (ResponseInterface|\Throwable|PromiseInterface<ResponseInterface, mixed>)>|null $queue The parameters to be passed to the append function, as an indexed array.
|
||||
* @param (callable(ResponseInterface|null): mixed)|null $onFulfilled Callback to invoke when the return value is fulfilled.
|
||||
* @param (callable(mixed): mixed)|null $onRejected Callback to invoke when the return value is rejected.
|
||||
*/
|
||||
public function __construct(
|
||||
#[\SensitiveParameter]
|
||||
?array $queue = null,
|
||||
?callable $onFulfilled = null,
|
||||
?callable $onRejected = null
|
||||
) {
|
||||
$this->onFulfilled = $onFulfilled;
|
||||
$this->onRejected = $onRejected;
|
||||
|
||||
if ($queue) {
|
||||
// array_values included for BC
|
||||
$this->append(...array_values($queue));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PromiseInterface<ResponseInterface, mixed>
|
||||
*/
|
||||
public function __invoke(
|
||||
#[\SensitiveParameter]
|
||||
RequestInterface $request,
|
||||
#[\SensitiveParameter]
|
||||
array $options
|
||||
): PromiseInterface {
|
||||
if (!$this->queue) {
|
||||
// Test-setup error (more requests made than responses queued);
|
||||
// intentionally a bare SPL exception, not a GuzzleException.
|
||||
throw new \OutOfBoundsException('Mock queue is empty');
|
||||
}
|
||||
|
||||
if (isset($options['delay']) && \is_numeric($options['delay'])) {
|
||||
\usleep((int) ($options['delay'] * 1000));
|
||||
}
|
||||
|
||||
if (isset($options['on_stats']) && !\is_callable($options['on_stats'])) {
|
||||
throw new InvalidArgumentException('on_stats must be callable');
|
||||
}
|
||||
|
||||
$this->lastRequest = $request;
|
||||
$this->lastOptions = $options;
|
||||
$response = \array_shift($this->queue);
|
||||
$onHeaders = null;
|
||||
$onHeadersResponse = null;
|
||||
|
||||
if (isset($options['on_headers'])) {
|
||||
if (!\is_callable($options['on_headers'])) {
|
||||
throw new InvalidArgumentException('on_headers must be callable');
|
||||
}
|
||||
|
||||
$onHeaders = $options['on_headers'];
|
||||
}
|
||||
|
||||
if (\is_callable($response)) {
|
||||
$response = $response($request, $options);
|
||||
}
|
||||
|
||||
$response = $response instanceof \Throwable
|
||||
? P\Create::rejectionFor($response)
|
||||
: P\Create::promiseFor($response);
|
||||
|
||||
if (\is_callable($onHeaders)) {
|
||||
$response = $response->then(
|
||||
static function (
|
||||
#[\SensitiveParameter]
|
||||
$value
|
||||
) use ($onHeaders, $request, &$onHeadersResponse) {
|
||||
if (!$value instanceof ResponseInterface) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
try {
|
||||
$onHeaders($value, $request);
|
||||
} catch (\Throwable $e) {
|
||||
$msg = 'An error was encountered during the on_headers event';
|
||||
$onHeadersResponse = $value;
|
||||
|
||||
throw new ResponseException($msg, $request, $value, $e);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
$promise = $response->then(
|
||||
function (
|
||||
#[\SensitiveParameter]
|
||||
$value
|
||||
) use ($request, $options): ?ResponseInterface {
|
||||
/** @var ResponseInterface|null $value */
|
||||
$this->invokeStats($request, $options, $value);
|
||||
if ($this->onFulfilled) {
|
||||
($this->onFulfilled)($value);
|
||||
}
|
||||
|
||||
if ($value !== null && isset($options['sink'])) {
|
||||
$contents = (string) $value->getBody();
|
||||
$sink = $options['sink'];
|
||||
|
||||
if (\is_resource($sink)) {
|
||||
\fwrite($sink, $contents);
|
||||
} elseif (\is_string($sink)) {
|
||||
\file_put_contents($sink, $contents);
|
||||
} elseif ($sink instanceof StreamInterface) {
|
||||
$sink->write($contents);
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
},
|
||||
function (
|
||||
#[\SensitiveParameter]
|
||||
$reason
|
||||
) use ($request, $options, &$onHeadersResponse): PromiseInterface {
|
||||
$this->invokeStats($request, $options, $onHeadersResponse, $reason);
|
||||
if ($this->onRejected) {
|
||||
($this->onRejected)($reason);
|
||||
}
|
||||
|
||||
return P\Create::rejectionFor($reason);
|
||||
}
|
||||
);
|
||||
|
||||
/** @var PromiseInterface<ResponseInterface, mixed> $promise */
|
||||
return $promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds one or more variadic requests, exceptions, callables, or promises
|
||||
* to the queue.
|
||||
*
|
||||
* @param mixed ...$values Responses, promises, throwables, or request-aware callables.
|
||||
*/
|
||||
public function append(
|
||||
#[\SensitiveParameter]
|
||||
...$values
|
||||
): void {
|
||||
foreach ($values as $value) {
|
||||
if ($value instanceof ResponseInterface
|
||||
|| $value instanceof \Throwable
|
||||
|| $value instanceof PromiseInterface
|
||||
|| \is_callable($value)
|
||||
) {
|
||||
$this->queue[] = $value;
|
||||
} else {
|
||||
throw new \TypeError('Expected a Response, Promise, Throwable or callable. Found '.\get_debug_type($value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last received request.
|
||||
*/
|
||||
public function getLastRequest(): ?RequestInterface
|
||||
{
|
||||
return $this->lastRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last received request options.
|
||||
*/
|
||||
public function getLastOptions(): array
|
||||
{
|
||||
return $this->lastOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of remaining items in the queue.
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return \count($this->queue);
|
||||
}
|
||||
|
||||
public function reset(): void
|
||||
{
|
||||
$this->queue = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $reason Promise or reason.
|
||||
*/
|
||||
private function invokeStats(
|
||||
#[\SensitiveParameter]
|
||||
RequestInterface $request,
|
||||
#[\SensitiveParameter]
|
||||
array $options,
|
||||
#[\SensitiveParameter]
|
||||
?ResponseInterface $response = null,
|
||||
#[\SensitiveParameter]
|
||||
$reason = null
|
||||
): void {
|
||||
if (isset($options['on_stats'])) {
|
||||
$transferTime = $options['transfer_time'] ?? 0.0;
|
||||
if (!\is_int($transferTime) && !\is_float($transferTime) && (!\is_string($transferTime) || !\is_numeric($transferTime))) {
|
||||
throw new InvalidArgumentException('transfer_time must be a number of seconds');
|
||||
}
|
||||
|
||||
$stats = new TransferStats($request, $response, (float) $transferTime, $reason);
|
||||
($options['on_stats'])($stats);
|
||||
}
|
||||
}
|
||||
}
|
||||
66
vendor/guzzlehttp/guzzle/src/Handler/Proxy.php
vendored
Normal file
66
vendor/guzzlehttp/guzzle/src/Handler/Proxy.php
vendored
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GuzzleHttp\Handler;
|
||||
|
||||
use GuzzleHttp\Promise\PromiseInterface;
|
||||
use GuzzleHttp\RequestOptions;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* Provides basic proxies for handlers.
|
||||
*/
|
||||
final class Proxy
|
||||
{
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends synchronous requests to a specific handler while sending all other
|
||||
* requests to another handler.
|
||||
*
|
||||
* @param callable(RequestInterface, array<array-key, mixed>): PromiseInterface<ResponseInterface, mixed> $default Handler used for normal responses
|
||||
* @param callable(RequestInterface, array<array-key, mixed>): PromiseInterface<ResponseInterface, mixed> $sync Handler used for synchronous responses.
|
||||
*
|
||||
* @return callable(RequestInterface, array<array-key, mixed>): PromiseInterface<ResponseInterface, mixed> Returns the composed handler.
|
||||
*/
|
||||
public static function wrapSync(callable $default, callable $sync): callable
|
||||
{
|
||||
return static function (
|
||||
#[\SensitiveParameter]
|
||||
RequestInterface $request,
|
||||
#[\SensitiveParameter]
|
||||
array $options
|
||||
) use ($default, $sync): PromiseInterface {
|
||||
return empty($options[RequestOptions::SYNCHRONOUS]) ? $default($request, $options) : $sync($request, $options);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends streaming requests to a streaming compatible handler while sending
|
||||
* all other requests to a default handler.
|
||||
*
|
||||
* This, for example, could be useful for taking advantage of the
|
||||
* performance benefits of curl while still supporting true streaming
|
||||
* through the StreamHandler.
|
||||
*
|
||||
* @param callable(RequestInterface, array<array-key, mixed>): PromiseInterface<ResponseInterface, mixed> $default Handler used for non-streaming responses
|
||||
* @param callable(RequestInterface, array<array-key, mixed>): PromiseInterface<ResponseInterface, mixed> $streaming Handler used for streaming responses
|
||||
*
|
||||
* @return callable(RequestInterface, array<array-key, mixed>): PromiseInterface<ResponseInterface, mixed> Returns the composed handler.
|
||||
*/
|
||||
public static function wrapStreaming(callable $default, callable $streaming): callable
|
||||
{
|
||||
return static function (
|
||||
#[\SensitiveParameter]
|
||||
RequestInterface $request,
|
||||
#[\SensitiveParameter]
|
||||
array $options
|
||||
) use ($default, $streaming): PromiseInterface {
|
||||
return empty($options['stream']) ? $default($request, $options) : $streaming($request, $options);
|
||||
};
|
||||
}
|
||||
}
|
||||
159
vendor/guzzlehttp/guzzle/src/Handler/ProxyEnv.php
vendored
Normal file
159
vendor/guzzlehttp/guzzle/src/Handler/ProxyEnv.php
vendored
Normal file
|
|
@ -0,0 +1,159 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GuzzleHttp\Handler;
|
||||
|
||||
use GuzzleHttp\ProxyOptions;
|
||||
use GuzzleHttp\ProxySelection;
|
||||
use GuzzleHttp\Psr7;
|
||||
use Psr\Http\Message\UriInterface;
|
||||
|
||||
/**
|
||||
* Resolves proxy configuration from the process environment with the same
|
||||
* semantics libcurl applies, shared by the built-in handlers: the cURL
|
||||
* handlers pin CURLOPT_PROXY and CURLOPT_NOPROXY explicitly so libcurl never
|
||||
* reads the environment itself, and the stream handler resolves the same way.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
final class ProxyEnv
|
||||
{
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the proxy selection for a request, falling back to the proxy
|
||||
* environment variables when the proxy request option makes no decision.
|
||||
*
|
||||
* The environment no_proxy list is tokenized the way libcurl tokenizes
|
||||
* it and matched here with the same rules as the proxy option's "no"
|
||||
* list, so behavior does not depend on the installed libcurl's matcher.
|
||||
*
|
||||
* @param mixed $proxyOption
|
||||
*/
|
||||
public static function resolveProxySelection(
|
||||
UriInterface $uri,
|
||||
#[\SensitiveParameter]
|
||||
$proxyOption
|
||||
): ProxySelection {
|
||||
$selection = ProxyOptions::resolve($uri, $proxyOption);
|
||||
|
||||
// Any option decision (proxy, bypassed, or disabled) is final; only
|
||||
// a none() selection leaves room for the environment.
|
||||
if ($selection->hasProxy() || $selection->shouldDisableProxy()) {
|
||||
return $selection;
|
||||
}
|
||||
|
||||
$envProxy = self::getProxyForScheme($uri->getScheme());
|
||||
if ($envProxy === null) {
|
||||
return $selection;
|
||||
}
|
||||
|
||||
$noProxy = self::getNoProxy();
|
||||
if ($noProxy !== null && ProxyOptions::isUriInNoProxy($uri, self::splitNoProxy($noProxy))) {
|
||||
return ProxySelection::bypassed();
|
||||
}
|
||||
|
||||
// $envProxy is never '' (empty env values are treated as unset).
|
||||
return ProxySelection::proxy($envProxy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the proxy to use for the given request scheme.
|
||||
*
|
||||
* The lookup mirrors libcurl for the http and https schemes the handlers
|
||||
* accept: the lowercase scheme-specific variable first, its uppercase
|
||||
* variant next (except for "http", where uppercase HTTP_PROXY is never
|
||||
* read), then all_proxy/ALL_PROXY.
|
||||
*
|
||||
* @return string|null The proxy to use; null when the environment
|
||||
* configures none.
|
||||
*/
|
||||
public static function getProxyForScheme(string $scheme): ?string
|
||||
{
|
||||
$scheme = Psr7\Utils::asciiToLower($scheme);
|
||||
$candidates = [$scheme.'_proxy'];
|
||||
if ($scheme !== 'http') {
|
||||
// Uppercase HTTP_PROXY is deliberately never consulted: a CGI
|
||||
// request header "Proxy:" becomes HTTP_PROXY in the environment.
|
||||
// See https://httpoxy.org for more information.
|
||||
$candidates[] = Psr7\Utils::asciiToUpper($scheme).'_PROXY';
|
||||
}
|
||||
$candidates[] = 'all_proxy';
|
||||
$candidates[] = 'ALL_PROXY';
|
||||
|
||||
foreach ($candidates as $name) {
|
||||
$value = self::getenv($name);
|
||||
if ($value !== null) {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null The no-proxy list; null when nothing is set.
|
||||
*/
|
||||
public static function getNoProxy(): ?string
|
||||
{
|
||||
foreach (['no_proxy', 'NO_PROXY'] as $name) {
|
||||
$value = self::getenv($name);
|
||||
if ($value !== null) {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits a no_proxy environment value into matchable entries.
|
||||
*
|
||||
* Entries may be separated by commas or blanks, the way libcurl tokenizes
|
||||
* the value.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public static function splitNoProxy(string $noProxy): array
|
||||
{
|
||||
$entries = [];
|
||||
|
||||
$split = \preg_split('/[\s,]+/', $noProxy);
|
||||
|
||||
if ($split === false) {
|
||||
throw new \RuntimeException('Unable to split the no_proxy value: '.\preg_last_error_msg());
|
||||
}
|
||||
|
||||
foreach ($split as $entry) {
|
||||
if ($entry !== '') {
|
||||
$entries[] = $entry;
|
||||
}
|
||||
}
|
||||
|
||||
return $entries;
|
||||
}
|
||||
|
||||
private static function getenv(string $name): ?string
|
||||
{
|
||||
// Windows environment variables are case-insensitive, so the
|
||||
// lowercase-only httpoxy defence does not hold there. Outside the
|
||||
// CLI SAPI on Windows, environment proxies are not resolved at all
|
||||
// (a safe-side divergence from libcurl).
|
||||
if (\PHP_OS_FAMILY === 'Windows' && \PHP_SAPI !== 'cli') {
|
||||
return null;
|
||||
}
|
||||
|
||||
// local_only: the OS environment and putenv() only - the same
|
||||
// environ(7) libcurl reads. SAPI request environments such as
|
||||
// fastcgi_param or SetEnv are deliberately excluded.
|
||||
$value = \getenv($name, true);
|
||||
|
||||
// libcurl's GetEnv (lib/getenv.c) treats variables set to an empty
|
||||
// string as unset on every version, so the lookup falls through to
|
||||
// the next candidate.
|
||||
return $value === false || $value === '' ? null : $value;
|
||||
}
|
||||
}
|
||||
256
vendor/guzzlehttp/guzzle/src/Handler/RequestFraming.php
vendored
Normal file
256
vendor/guzzlehttp/guzzle/src/Handler/RequestFraming.php
vendored
Normal file
|
|
@ -0,0 +1,256 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GuzzleHttp\Handler;
|
||||
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use GuzzleHttp\NonSerializableTrait;
|
||||
use GuzzleHttp\Psr7;
|
||||
use GuzzleHttp\Psr7\Exception\TimeoutException;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
|
||||
/**
|
||||
* Validates and normalizes request framing before a handler performs I/O.
|
||||
*
|
||||
* Body size describes the bytes available under handler rewind semantics.
|
||||
* Content-Length is the selected transport boundary and may remain unknown.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
final class RequestFraming
|
||||
{
|
||||
use NonSerializableTrait;
|
||||
|
||||
public RequestInterface $request;
|
||||
|
||||
/**
|
||||
* Number of bytes available after applying handler rewind semantics, if
|
||||
* known.
|
||||
*/
|
||||
public ?int $bodySize;
|
||||
|
||||
/** Canonical Content-Length boundary selected for transport, if any. */
|
||||
public ?int $contentLength;
|
||||
|
||||
private function __construct(RequestInterface $request, ?int $bodySize, ?int $contentLength)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->bodySize = $bodySize;
|
||||
$this->contentLength = $contentLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finalizes request framing for a handler dispatch.
|
||||
*
|
||||
* When $sendBody is false, body-dependent validation and size probing are
|
||||
* skipped. Content-Length is still canonicalized and Transfer-Encoding is
|
||||
* removed.
|
||||
*
|
||||
* @throws RequestException when framing or body metadata is unsafe
|
||||
*/
|
||||
public static function analyze(
|
||||
#[\SensitiveParameter]
|
||||
RequestInterface $request,
|
||||
bool $sendBody = true
|
||||
): self {
|
||||
try {
|
||||
$length = HeaderProcessor::parseContentLength($request->getHeader('Content-Length'));
|
||||
} catch (\RuntimeException $e) {
|
||||
throw new RequestException('Invalid Content-Length request header: '.$e->getMessage(), $request, 0, $e);
|
||||
}
|
||||
|
||||
try {
|
||||
HeaderProcessor::assertContentLengthWithinPlatformLimit($length);
|
||||
} catch (\OverflowException $e) {
|
||||
throw new RequestException($e->getMessage(), $request, 0, $e);
|
||||
}
|
||||
|
||||
$contentLength = HeaderProcessor::contentLengthToInt($length);
|
||||
if ($length !== null) {
|
||||
$request = $request->withHeader('Content-Length', $length);
|
||||
}
|
||||
|
||||
if (!$sendBody) {
|
||||
return new self($request->withoutHeader('Transfer-Encoding'), null, $contentLength);
|
||||
}
|
||||
|
||||
$transferEncoding = $request->getHeader('Transfer-Encoding');
|
||||
if ($length !== null && $transferEncoding !== []) {
|
||||
throw new RequestException(
|
||||
'A request must not contain both Content-Length and Transfer-Encoding',
|
||||
$request
|
||||
);
|
||||
}
|
||||
|
||||
if ($transferEncoding !== []) {
|
||||
$tokens = [];
|
||||
foreach ($transferEncoding as $value) {
|
||||
foreach (\explode(',', $value) as $part) {
|
||||
$tokens[] = \trim($part, " \t");
|
||||
}
|
||||
}
|
||||
|
||||
if (\count($tokens) !== 1 || !Psr7\Utils::caselessEquals($tokens[0], 'chunked') || $request->getProtocolVersion() !== '1.1') {
|
||||
throw new RequestException('Unsupported Transfer-Encoding request header', $request);
|
||||
}
|
||||
}
|
||||
|
||||
$bodySize = self::bodySize($request);
|
||||
if ($bodySize !== null && $contentLength !== null && $bodySize !== $contentLength) {
|
||||
throw new RequestException('Content-Length does not match the request body size', $request);
|
||||
}
|
||||
|
||||
if ($bodySize === null && $contentLength === null && $request->getProtocolVersion() === '1.0') {
|
||||
throw new RequestException('An unknown-size HTTP/1.0 request body requires Content-Length', $request);
|
||||
}
|
||||
|
||||
if ($length === null && $bodySize !== null && ($bodySize > 0 || \in_array($request->getMethod(), ['PUT', 'POST'], true))) {
|
||||
$contentLength = $bodySize;
|
||||
$request = $request->withHeader('Content-Length', (string) $bodySize);
|
||||
}
|
||||
|
||||
return new self($request->withoutHeader('Transfer-Encoding'), $bodySize, $contentLength);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of bytes available for dispatch, or null when unknown.
|
||||
*
|
||||
* Seekable bodies use their total size because handlers rewind them.
|
||||
* Positioned non-seekable bodies use the total size minus their current
|
||||
* position.
|
||||
*
|
||||
* @throws RequestException when body metadata cannot be read safely
|
||||
*/
|
||||
public static function bodySize(
|
||||
#[\SensitiveParameter]
|
||||
RequestInterface $request
|
||||
): ?int {
|
||||
$body = $request->getBody();
|
||||
|
||||
try {
|
||||
$size = $body->getSize();
|
||||
if ($size === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($size < 0) {
|
||||
throw new \RuntimeException('Request body size must not be negative');
|
||||
}
|
||||
|
||||
$seekable = $body->isSeekable();
|
||||
} catch (\Exception $e) {
|
||||
throw self::bodyException(
|
||||
$request,
|
||||
$e,
|
||||
'Timed out while determining the request body size',
|
||||
'Failed to determine the request body size'
|
||||
);
|
||||
}
|
||||
|
||||
if ($seekable) {
|
||||
return $size;
|
||||
}
|
||||
|
||||
try {
|
||||
$position = $body->tell();
|
||||
} catch (\RuntimeException $e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($position < 0 || $position > $size) {
|
||||
throw new RequestException('The request body position is outside the stream size', $request);
|
||||
}
|
||||
|
||||
return $size - $position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Materializes the body, stopping at the selected Content-Length when
|
||||
* present.
|
||||
*
|
||||
* @throws RequestException when the body cannot be fully rewound or read
|
||||
*/
|
||||
public function materialize(): string
|
||||
{
|
||||
$body = $this->request->getBody();
|
||||
|
||||
if ($this->contentLength === null) {
|
||||
try {
|
||||
return (string) $body;
|
||||
} catch (\Exception $e) {
|
||||
throw self::bodyException(
|
||||
$this->request,
|
||||
$e,
|
||||
'Timed out while reading the request body',
|
||||
'Failed to read the request body'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->contentLength === 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
try {
|
||||
if ($body->isSeekable()) {
|
||||
$body->rewind();
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw self::bodyException(
|
||||
$this->request,
|
||||
$e,
|
||||
'Timed out while rewinding the request body',
|
||||
'Failed to rewind the request body'
|
||||
);
|
||||
}
|
||||
|
||||
$contents = '';
|
||||
$remaining = $this->contentLength;
|
||||
while ($remaining > 0) {
|
||||
$limit = \min(8192, $remaining);
|
||||
|
||||
try {
|
||||
$chunk = $body->read($limit);
|
||||
} catch (\Exception $e) {
|
||||
throw self::bodyException(
|
||||
$this->request,
|
||||
$e,
|
||||
'Timed out while reading the request body',
|
||||
'Failed to read the request body'
|
||||
);
|
||||
}
|
||||
|
||||
if ($chunk === '') {
|
||||
throw new RequestException(
|
||||
'Request body ended before the declared Content-Length was reached',
|
||||
$this->request
|
||||
);
|
||||
}
|
||||
|
||||
if (\strlen($chunk) > $limit) {
|
||||
throw new RequestException('Request body stream returned more bytes than requested', $this->request);
|
||||
}
|
||||
|
||||
$contents .= $chunk;
|
||||
$remaining -= \strlen($chunk);
|
||||
}
|
||||
|
||||
return $contents;
|
||||
}
|
||||
|
||||
private static function bodyException(
|
||||
#[\SensitiveParameter]
|
||||
RequestInterface $request,
|
||||
#[\SensitiveParameter]
|
||||
\Exception $exception,
|
||||
string $timeoutMessage,
|
||||
string $fallbackMessage
|
||||
): RequestException {
|
||||
$message = $exception instanceof TimeoutException
|
||||
? $timeoutMessage
|
||||
: ($exception->getMessage() !== '' ? $exception->getMessage() : $fallbackMessage);
|
||||
|
||||
return new RequestException($message, $request, 0, $exception);
|
||||
}
|
||||
}
|
||||
2077
vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php
vendored
Normal file
2077
vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php
vendored
Normal file
File diff suppressed because it is too large
Load diff
583
vendor/guzzlehttp/guzzle/src/Handler/StreamTlsSessionCache.php
vendored
Normal file
583
vendor/guzzlehttp/guzzle/src/Handler/StreamTlsSessionCache.php
vendored
Normal file
|
|
@ -0,0 +1,583 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GuzzleHttp\Handler;
|
||||
|
||||
use GuzzleHttp\Exception\InvalidArgumentException;
|
||||
use GuzzleHttp\HostIdentity;
|
||||
use GuzzleHttp\NonSerializableTrait;
|
||||
use GuzzleHttp\Psr7;
|
||||
use Openssl\Session;
|
||||
|
||||
/**
|
||||
* Per-handler in-memory TLS session resumption cache for the stream handler.
|
||||
*
|
||||
* Backed by the OpenSSL TLS session API added in PHP 8.6. A session is only
|
||||
* ever replayed for an identical TLS identity: the non-secret identity is
|
||||
* encoded in the lookup key and secret material is matched in constant time.
|
||||
* TLS resumption reuses the original certificate-chain verification result
|
||||
* instead of building and verifying the chain again. Guzzle includes ambient
|
||||
* trust configuration paths in the cache identity, but cannot detect
|
||||
* trust-store contents rewritten at an unchanged path. Recreate the handler
|
||||
* or disable transport sharing when trust changes must take effect
|
||||
* immediately.
|
||||
*
|
||||
* New sessions are held temporarily and committed only after the HTTPS stream
|
||||
* opens successfully. If PHP rejects peer verification or another stream-open
|
||||
* step fails, any session reported during that attempt is discarded.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
final class StreamTlsSessionCache
|
||||
{
|
||||
use NonSerializableTrait;
|
||||
|
||||
/**
|
||||
* Sessions retained per peer. libcurl uses 2 to buffer single-use TLS 1.3
|
||||
* tickets; the synchronous stream handler does not need more.
|
||||
*/
|
||||
public const MAX_SESSIONS_PER_KEY = 2;
|
||||
|
||||
/**
|
||||
* TLS 1.3 tickets should not live longer than RFC 8446 allows. All
|
||||
* pre-TLS-1.3 sessions use libcurl's tighter one-day cap.
|
||||
*/
|
||||
private const MAX_TLS13_LIFETIME = 604800;
|
||||
private const MAX_PRE_TLS13_LIFETIME = 86400;
|
||||
|
||||
private const USER_MANAGED_SESSION_OPTIONS = [
|
||||
'session_cache' => true,
|
||||
'session_cache_size' => true,
|
||||
'session_data' => true,
|
||||
'session_get_cb' => true,
|
||||
'session_id_context' => true,
|
||||
'session_new_cb' => true,
|
||||
'session_remove_cb' => true,
|
||||
'session_stream' => true,
|
||||
'session_timeout' => true,
|
||||
];
|
||||
|
||||
private const USER_MANAGED_PSK_OPTIONS = [
|
||||
'psk_client_cb' => true,
|
||||
'psk_server_cb' => true,
|
||||
];
|
||||
|
||||
/**
|
||||
* TLS 1.3 early data (0-RTT) options are deliberately never shared: an
|
||||
* injected cached session would let PHP send the replayable early data
|
||||
* payload ahead of the HTTP request.
|
||||
*/
|
||||
private const USER_MANAGED_EARLY_DATA_OPTIONS = [
|
||||
'early_data' => true,
|
||||
'early_data_cb' => true,
|
||||
'max_early_data' => true,
|
||||
];
|
||||
|
||||
/**
|
||||
* File/path-bearing SSL context options are deliberately not shared: their
|
||||
* contents can change outside this handler.
|
||||
*/
|
||||
private const PATH_OPTIONS = [
|
||||
'SNI_server_certs' => true,
|
||||
'cafile' => true,
|
||||
'capath' => true,
|
||||
'dh_param' => true,
|
||||
'local_cert' => true,
|
||||
'local_pk' => true,
|
||||
];
|
||||
|
||||
private const CERT_CAPTURE_OPTIONS = [
|
||||
'capture_peer_cert' => true,
|
||||
'capture_peer_cert_chain' => true,
|
||||
];
|
||||
|
||||
/**
|
||||
* Scalar custom SSL context options that are known to be self-contained
|
||||
* and safe to include in the TLS session cache identity.
|
||||
*/
|
||||
private const CUSTOM_SCALAR_KEYABLE_OPTIONS = [
|
||||
'SNI_enabled' => true,
|
||||
'allow_self_signed' => true,
|
||||
'alpn_protocols' => true,
|
||||
'ciphers' => true,
|
||||
'crypto_method' => true,
|
||||
'disable_compression' => true,
|
||||
'max_proto_version' => true,
|
||||
'min_proto_version' => true,
|
||||
'peer_name' => true,
|
||||
'security_level' => true,
|
||||
'verify_depth' => true,
|
||||
'verify_peer' => true,
|
||||
'verify_peer_name' => true,
|
||||
];
|
||||
|
||||
private const INVALID_PEER_FINGERPRINT_REASON = 'the SSL context option "peer_fingerprint" must be a string or a non-empty, flat array with string algorithm names and string fingerprints.';
|
||||
|
||||
private int $maxKeys;
|
||||
|
||||
/**
|
||||
* @var array<string, list<array{session: Session, credentials: string, expiresAt: int, singleUse: bool}>>
|
||||
*/
|
||||
private array $sessions = [];
|
||||
|
||||
public function __construct(int $maxKeys)
|
||||
{
|
||||
if ($maxKeys < 1) {
|
||||
throw new InvalidArgumentException('maxKeys must be a positive integer.');
|
||||
}
|
||||
|
||||
$this->maxKeys = $maxKeys;
|
||||
}
|
||||
|
||||
public static function isSupported(): bool
|
||||
{
|
||||
// Any PHP 8.6 build qualifies, including pre-release and nightly
|
||||
// builds; the class check keeps unstable builds that do not carry
|
||||
// the final API fail-closed.
|
||||
return \PHP_VERSION_ID >= 80600 && \class_exists(Session::class, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $ssl The assembled 'ssl' stream context array.
|
||||
* @param array $customSsl The user-supplied stream_context['ssl'] array.
|
||||
*/
|
||||
public static function unsupportedContextReason(array $ssl, array $customSsl = []): ?string
|
||||
{
|
||||
foreach ($customSsl as $key => $value) {
|
||||
if (
|
||||
!isset(self::CUSTOM_SCALAR_KEYABLE_OPTIONS[$key])
|
||||
&& !isset(self::PATH_OPTIONS[$key])
|
||||
&& !isset(self::USER_MANAGED_SESSION_OPTIONS[$key])
|
||||
&& !isset(self::USER_MANAGED_PSK_OPTIONS[$key])
|
||||
&& !isset(self::USER_MANAGED_EARLY_DATA_OPTIONS[$key])
|
||||
&& !isset(self::CERT_CAPTURE_OPTIONS[$key])
|
||||
&& $key !== 'no_ticket'
|
||||
&& $key !== 'peer_fingerprint'
|
||||
) {
|
||||
return \sprintf('the custom SSL context option "%s" is not known to be safe for TLS session sharing.', Psr7\DiagnosticValue::escape((string) $key));
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($ssl as $key => $value) {
|
||||
if (isset(self::PATH_OPTIONS[$key])) {
|
||||
return \sprintf('the SSL context option "%s" uses file or path state that cannot be safely shared.', Psr7\DiagnosticValue::escape((string) $key));
|
||||
}
|
||||
|
||||
if (isset(self::USER_MANAGED_SESSION_OPTIONS[$key])) {
|
||||
return \sprintf('the SSL context option "%s" is user-managed TLS session state.', Psr7\DiagnosticValue::escape((string) $key));
|
||||
}
|
||||
|
||||
if (isset(self::USER_MANAGED_PSK_OPTIONS[$key])) {
|
||||
return \sprintf('the SSL context option "%s" is user-managed TLS PSK state.', Psr7\DiagnosticValue::escape((string) $key));
|
||||
}
|
||||
|
||||
if (isset(self::USER_MANAGED_EARLY_DATA_OPTIONS[$key])) {
|
||||
return \sprintf('the SSL context option "%s" is user-managed TLS early data state.', Psr7\DiagnosticValue::escape((string) $key));
|
||||
}
|
||||
|
||||
if (isset(self::CERT_CAPTURE_OPTIONS[$key]) && $value) {
|
||||
return \sprintf('the SSL context option "%s" requires a fresh peer certificate handshake.', Psr7\DiagnosticValue::escape((string) $key));
|
||||
}
|
||||
|
||||
if ($key === 'no_ticket' && $value) {
|
||||
return 'the SSL context option "no_ticket" disables TLS ticket sharing.';
|
||||
}
|
||||
|
||||
if ($key === 'peer_fingerprint') {
|
||||
if (!self::isPeerFingerprint($value)) {
|
||||
return self::INVALID_PEER_FINGERPRINT_REASON;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!self::isCanonicalScalar($value)) {
|
||||
return \sprintf('the SSL context option "%s" cannot be safely included in the TLS session cache identity.', Psr7\DiagnosticValue::escape((string) $key));
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the non-secret lookup key: host/port plus every TLS parameter that
|
||||
* defines the verification/identity context. Keyed on the connection host
|
||||
* a transport reads, with numeric IPv4 spellings folded to one dotted
|
||||
* quad; names are never resolved. Secret material is excluded.
|
||||
*
|
||||
* @param array $ssl The assembled 'ssl' stream context array.
|
||||
*/
|
||||
public static function peerKey(
|
||||
string $host,
|
||||
?int $port,
|
||||
#[\SensitiveParameter]
|
||||
array $ssl
|
||||
): string {
|
||||
$identity = [
|
||||
'schema' => 'guzzle-stream-tls-session-v1',
|
||||
'runtime' => self::runtimeIdentity(),
|
||||
'peer' => [
|
||||
'host' => self::canonicalHost($host),
|
||||
'port' => $port,
|
||||
],
|
||||
'ssl' => self::canonicalPeerSslContext($ssl),
|
||||
];
|
||||
|
||||
return \hash('sha256', \serialize($identity));
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the secret-aware credential fingerprint matched in constant time,
|
||||
* keeping the passphrase out of the loggable peer key.
|
||||
*
|
||||
* Every credential-bearing context is currently rejected by
|
||||
* unsupportedContextReason() before sharing, so fingerprints can only
|
||||
* diverge if the allow-lists are ever widened; the constant-time match is
|
||||
* retained as defense in depth for that case.
|
||||
*
|
||||
* @param array $ssl The assembled 'ssl' stream context array.
|
||||
*/
|
||||
public static function credentialFingerprint(array $ssl): string
|
||||
{
|
||||
$material = [
|
||||
'local_cert' => isset($ssl['local_cert']) && \is_string($ssl['local_cert']) ? self::pathIdentity($ssl['local_cert']) : null,
|
||||
'local_pk' => isset($ssl['local_pk']) && \is_string($ssl['local_pk']) ? self::pathIdentity($ssl['local_pk']) : null,
|
||||
'passphrase' => isset($ssl['passphrase']) && \is_string($ssl['passphrase']) ? $ssl['passphrase'] : null,
|
||||
];
|
||||
|
||||
return \hash('sha256', \serialize($material));
|
||||
}
|
||||
|
||||
public function find(string $key, string $credentials): ?Session
|
||||
{
|
||||
if (!isset($this->sessions[$key])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$now = \time();
|
||||
$entries = $this->sessions[$key];
|
||||
$found = null;
|
||||
|
||||
foreach ($entries as $i => $entry) {
|
||||
if ($entry['expiresAt'] <= $now) {
|
||||
unset($entries[$i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!\hash_equals($entry['credentials'], $credentials)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$entry['session']->isResumable()) {
|
||||
unset($entries[$i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
$found = $entry['session'];
|
||||
|
||||
// TLS 1.3 tickets are single-use; consume on take.
|
||||
if ($entry['singleUse']) {
|
||||
unset($entries[$i]);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if ($entries === []) {
|
||||
unset($this->sessions[$key]);
|
||||
} else {
|
||||
$this->sessions[$key] = \array_values($entries);
|
||||
if ($found !== null) {
|
||||
$this->touch($key);
|
||||
}
|
||||
}
|
||||
|
||||
return $found;
|
||||
}
|
||||
|
||||
public function store(
|
||||
string $key,
|
||||
string $credentials,
|
||||
#[\SensitiveParameter]
|
||||
Session $session
|
||||
): void {
|
||||
if (!$session->isResumable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$expiresAt = self::expiry($session);
|
||||
if ($expiresAt === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$list = $this->sessions[$key] ?? [];
|
||||
$list[] = [
|
||||
'session' => $session,
|
||||
'credentials' => $credentials,
|
||||
'expiresAt' => $expiresAt,
|
||||
'singleUse' => self::isTls13($session),
|
||||
];
|
||||
|
||||
if (\count($list) > self::MAX_SESSIONS_PER_KEY) {
|
||||
$list = \array_slice($list, -self::MAX_SESSIONS_PER_KEY);
|
||||
}
|
||||
|
||||
$this->sessions[$key] = $list;
|
||||
$this->touch($key);
|
||||
$this->evictExcessKeys();
|
||||
}
|
||||
|
||||
private function touch(string $key): void
|
||||
{
|
||||
if (!isset($this->sessions[$key])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$value = $this->sessions[$key];
|
||||
unset($this->sessions[$key]);
|
||||
$this->sessions[$key] = $value;
|
||||
}
|
||||
|
||||
private function evictExcessKeys(): void
|
||||
{
|
||||
while (\count($this->sessions) > $this->maxKeys) {
|
||||
\array_shift($this->sessions);
|
||||
}
|
||||
}
|
||||
|
||||
private static function isTls13(
|
||||
#[\SensitiveParameter]
|
||||
Session $session
|
||||
): bool {
|
||||
$protocol = $session->getProtocol();
|
||||
|
||||
return $protocol !== null && Psr7\Utils::caselessContains($protocol, '1.3');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the absolute expiry timestamp, or null when the session must
|
||||
* not be cached.
|
||||
*/
|
||||
private static function expiry(
|
||||
#[\SensitiveParameter]
|
||||
Session $session
|
||||
): ?int {
|
||||
return self::expiryFromLifetimes(
|
||||
self::isTls13($session),
|
||||
$session->hasTicket(),
|
||||
$session->getTicketLifetimeHint(),
|
||||
$session->getTimeout(),
|
||||
$session->getCreatedAt(),
|
||||
\time()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decides the absolute expiry timestamp from a session's scalar lifetime
|
||||
* attributes, or null when the session must not be cached.
|
||||
*
|
||||
* A non-positive session timeout is never cached. TLS 1.3 resumption
|
||||
* requires a New Session Ticket, so a TLS 1.3 session without a ticket
|
||||
* or without a positive RFC 8446 ticket lifetime is not cached, and the
|
||||
* ticket lifetime bounds the expiry together with the session timeout
|
||||
* and the seven-day cap. Pre-TLS-1.3 tickets treat a zero or missing
|
||||
* lifetime hint as unspecified per RFC 5077, so only a positive hint
|
||||
* tightens the session timeout and the one-day cap. An expiry that has
|
||||
* already passed is not cached.
|
||||
*/
|
||||
private static function expiryFromLifetimes(bool $isTls13, bool $hasTicket, ?int $ticketLifetimeHint, int $timeout, int $createdAt, int $now): ?int
|
||||
{
|
||||
if ($timeout <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$lifetime = \min($timeout, $isTls13 ? self::MAX_TLS13_LIFETIME : self::MAX_PRE_TLS13_LIFETIME);
|
||||
|
||||
if ($isTls13) {
|
||||
if (!$hasTicket || $ticketLifetimeHint === null || $ticketLifetimeHint <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$lifetime = \min($lifetime, $ticketLifetimeHint);
|
||||
} elseif ($hasTicket && $ticketLifetimeHint !== null && $ticketLifetimeHint > 0) {
|
||||
$lifetime = \min($lifetime, $ticketLifetimeHint);
|
||||
}
|
||||
|
||||
$expiresAt = $createdAt + $lifetime;
|
||||
|
||||
return $expiresAt > $now ? $expiresAt : null;
|
||||
}
|
||||
|
||||
private static function runtimeIdentity(): array
|
||||
{
|
||||
return [
|
||||
'php' => \PHP_VERSION_ID,
|
||||
'openssl' => \defined('OPENSSL_VERSION_NUMBER') ? \OPENSSL_VERSION_NUMBER : null,
|
||||
'trust' => [
|
||||
'openssl.cafile' => (string) \ini_get('openssl.cafile'),
|
||||
'openssl.capath' => (string) \ini_get('openssl.capath'),
|
||||
'SSL_CERT_FILE' => (string) \getenv('SSL_CERT_FILE'),
|
||||
'SSL_CERT_DIR' => (string) \getenv('SSL_CERT_DIR'),
|
||||
'cwd' => \getcwd(),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the host identity hashed into the cache key. Valid bracketed
|
||||
* IPv6 literals are canonicalized to their RFC 5952 form so equivalent
|
||||
* spellings of one address share a single session entry; other valid
|
||||
* hosts, such as reg-names and IPvFuture literals, fall back to ASCII
|
||||
* case folding. Text that is not a valid RFC 3986 host, such as
|
||||
* zone-bearing or malformed bracketed literals, must never become a
|
||||
* usable cache key, so it is rejected.
|
||||
*/
|
||||
private static function canonicalHost(string $host): string
|
||||
{
|
||||
if (!Psr7\Rfc3986::isValidHost($host)) {
|
||||
throw new InvalidArgumentException('Hosts used in the TLS session cache identity must be valid RFC 3986 hosts.');
|
||||
}
|
||||
|
||||
return HostIdentity::canonicalHost($host);
|
||||
}
|
||||
|
||||
private static function canonicalPeerSslContext(
|
||||
#[\SensitiveParameter]
|
||||
array $ssl
|
||||
): array {
|
||||
$context = [];
|
||||
|
||||
foreach ($ssl as $key => $value) {
|
||||
if (isset(self::USER_MANAGED_SESSION_OPTIONS[$key]) || isset(self::USER_MANAGED_PSK_OPTIONS[$key]) || isset(self::USER_MANAGED_EARLY_DATA_OPTIONS[$key]) || $key === 'passphrase') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($key === 'peer_name' && \is_string($value)) {
|
||||
$context[$key] = ['string', self::canonicalHost($value)];
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($key === 'peer_fingerprint') {
|
||||
$context[$key] = self::canonicalPeerFingerprint($value);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (\in_array($key, ['cafile', 'capath', 'local_cert', 'local_pk'], true) && \is_string($value)) {
|
||||
$context[$key] = self::pathIdentity($value);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$context[$key] = self::canonicalScalar($value);
|
||||
}
|
||||
|
||||
\ksort($context);
|
||||
|
||||
return $context;
|
||||
}
|
||||
|
||||
private static function pathIdentity(string $path): array
|
||||
{
|
||||
$realPath = \realpath($path);
|
||||
|
||||
return [
|
||||
'path',
|
||||
$realPath !== false ? $realPath : $path,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
private static function isCanonicalScalar($value): bool
|
||||
{
|
||||
return $value === null
|
||||
|| \is_bool($value)
|
||||
|| \is_int($value)
|
||||
|| \is_float($value)
|
||||
|| \is_string($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
private static function isPeerFingerprint($value): bool
|
||||
{
|
||||
if (\is_string($value)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!\is_array($value) || $value === []) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($value as $algorithm => $fingerprint) {
|
||||
if (!\is_string($algorithm) || !\is_string($fingerprint)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return array{0: string, 1: mixed}
|
||||
*/
|
||||
private static function canonicalScalar($value): array
|
||||
{
|
||||
if ($value === null) {
|
||||
return ['null', null];
|
||||
}
|
||||
|
||||
if (\is_bool($value)) {
|
||||
return ['bool', $value];
|
||||
}
|
||||
|
||||
if (\is_int($value)) {
|
||||
return ['int', $value];
|
||||
}
|
||||
|
||||
if (\is_float($value)) {
|
||||
return ['float', \bin2hex(\pack('E', $value))];
|
||||
}
|
||||
|
||||
if (\is_string($value)) {
|
||||
return ['string', $value];
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException('SSL context values used in the TLS session cache identity must be scalar or null.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return array{0: string, 1: mixed}
|
||||
*/
|
||||
private static function canonicalPeerFingerprint($value): array
|
||||
{
|
||||
if (!self::isPeerFingerprint($value)) {
|
||||
throw new InvalidArgumentException(self::INVALID_PEER_FINGERPRINT_REASON);
|
||||
}
|
||||
|
||||
if (\is_string($value)) {
|
||||
return ['string', $value];
|
||||
}
|
||||
|
||||
if (!\is_array($value)) {
|
||||
throw new InvalidArgumentException(self::INVALID_PEER_FINGERPRINT_REASON);
|
||||
}
|
||||
|
||||
$items = [];
|
||||
foreach ($value as $algorithm => $fingerprint) {
|
||||
$items[$algorithm] = ['string', $fingerprint];
|
||||
}
|
||||
\ksort($items, \SORT_STRING);
|
||||
|
||||
return ['map', $items];
|
||||
}
|
||||
}
|
||||
41
vendor/guzzlehttp/guzzle/src/Handler/Timeout.php
vendored
Normal file
41
vendor/guzzlehttp/guzzle/src/Handler/Timeout.php
vendored
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GuzzleHttp\Handler;
|
||||
|
||||
use GuzzleHttp\Exception\InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class Timeout
|
||||
{
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a request timeout option to integer milliseconds.
|
||||
*
|
||||
* @param mixed $value
|
||||
*/
|
||||
public static function toMilliseconds($value, string $option): int
|
||||
{
|
||||
if (!\is_int($value) && !\is_float($value) && (!\is_string($value) || !\is_numeric($value))) {
|
||||
throw new InvalidArgumentException($option.' must be a number of seconds');
|
||||
}
|
||||
|
||||
$seconds = (float) $value;
|
||||
if (!\is_finite($seconds) || $seconds < 0) {
|
||||
throw new InvalidArgumentException($option.' must be 0 or greater than or equal to 0.001 seconds');
|
||||
}
|
||||
|
||||
$milliseconds = (int) ($seconds * 1000);
|
||||
if ($seconds > 0 && $milliseconds === 0) {
|
||||
throw new InvalidArgumentException($option.' must be 0 or greater than or equal to 0.001 seconds');
|
||||
}
|
||||
|
||||
return $milliseconds;
|
||||
}
|
||||
}
|
||||
70
vendor/guzzlehttp/guzzle/src/Handler/TlsVersion.php
vendored
Normal file
70
vendor/guzzlehttp/guzzle/src/Handler/TlsVersion.php
vendored
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GuzzleHttp\Handler;
|
||||
|
||||
use GuzzleHttp\Exception\InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class TlsVersion
|
||||
{
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
public static function ordinal(string $option, $value): int
|
||||
{
|
||||
if ($value === \STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT) {
|
||||
return 10;
|
||||
}
|
||||
if ($value === \STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT) {
|
||||
return 11;
|
||||
}
|
||||
if ($value === \STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT) {
|
||||
return 12;
|
||||
}
|
||||
if ($value === \STREAM_CRYPTO_METHOD_TLSv1_3_CLIENT) {
|
||||
return 13;
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException(\sprintf('Invalid %s request option: unknown version provided', $option));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $min
|
||||
* @param mixed $max
|
||||
*/
|
||||
public static function assertRange($min, $max): void
|
||||
{
|
||||
if ($min === null || $max === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (self::ordinal('crypto_method_max', $max) < self::ordinal('crypto_method', $min)) {
|
||||
throw new InvalidArgumentException('Invalid crypto_method_max request option: maximum TLS version must be greater than or equal to crypto_method');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
public static function streamProtocolVersion(string $option, $value): int
|
||||
{
|
||||
if ($value === \STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT) {
|
||||
return \STREAM_CRYPTO_PROTO_TLSv1_0;
|
||||
}
|
||||
if ($value === \STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT) {
|
||||
return \STREAM_CRYPTO_PROTO_TLSv1_1;
|
||||
}
|
||||
if ($value === \STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT) {
|
||||
return \STREAM_CRYPTO_PROTO_TLSv1_2;
|
||||
}
|
||||
if ($value === \STREAM_CRYPTO_METHOD_TLSv1_3_CLIENT) {
|
||||
return \STREAM_CRYPTO_PROTO_TLSv1_3;
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException(\sprintf('Invalid %s request option: unknown version provided', $option));
|
||||
}
|
||||
}
|
||||
62
vendor/guzzlehttp/guzzle/src/Handler/TransferByteCounter.php
vendored
Normal file
62
vendor/guzzlehttp/guzzle/src/Handler/TransferByteCounter.php
vendored
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GuzzleHttp\Handler;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class TransferByteCounter
|
||||
{
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
public static function progressValueToInt($value): int
|
||||
{
|
||||
if (\is_int($value)) {
|
||||
if ($value < 0) {
|
||||
throw new \OverflowException('Progress byte count exceeds the maximum integer size supported on this platform');
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (!\is_float($value)) {
|
||||
throw new \UnexpectedValueException('Progress byte count must be an integer or float');
|
||||
}
|
||||
|
||||
if (
|
||||
!\is_finite($value)
|
||||
|| $value < 0
|
||||
|| $value > \PHP_INT_MAX
|
||||
|| (\PHP_INT_SIZE === 8 && $value >= (float) \PHP_INT_MAX)
|
||||
) {
|
||||
throw new \OverflowException('Progress byte count exceeds the maximum integer size supported on this platform');
|
||||
}
|
||||
|
||||
$intValue = (int) $value;
|
||||
if ($intValue < 0) {
|
||||
throw new \OverflowException('Progress byte count exceeds the maximum integer size supported on this platform');
|
||||
}
|
||||
|
||||
return $intValue;
|
||||
}
|
||||
|
||||
public static function add(int $current, int $delta, string $message): int
|
||||
{
|
||||
if ($current < 0 || $delta < 0) {
|
||||
throw new \OverflowException($message);
|
||||
}
|
||||
|
||||
if ($delta > \PHP_INT_MAX - $current) {
|
||||
throw new \OverflowException($message);
|
||||
}
|
||||
|
||||
return $current + $delta;
|
||||
}
|
||||
}
|
||||
39
vendor/guzzlehttp/guzzle/src/Handler/UriDiagnostic.php
vendored
Normal file
39
vendor/guzzlehttp/guzzle/src/Handler/UriDiagnostic.php
vendored
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GuzzleHttp\Handler;
|
||||
|
||||
use GuzzleHttp\Psr7;
|
||||
use Psr\Http\Message\UriInterface;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class UriDiagnostic
|
||||
{
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public static function redactInMessage(
|
||||
#[\SensitiveParameter]
|
||||
string $message,
|
||||
#[\SensitiveParameter]
|
||||
UriInterface $uri
|
||||
): string {
|
||||
$message = Psr7\Utils::redactUserInfoInString($message, (string) $uri);
|
||||
|
||||
$query = $uri->getQuery();
|
||||
if ($query !== '') {
|
||||
$message = \str_replace('?'.$query, '', $message);
|
||||
}
|
||||
|
||||
$fragment = $uri->getFragment();
|
||||
if ($fragment !== '') {
|
||||
$message = \str_replace('#'.$fragment, '', $message);
|
||||
}
|
||||
|
||||
return Psr7\DiagnosticValue::escape($message);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue