diff options
-rw-r--r-- | src/PSR7Client.php | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/src/PSR7Client.php b/src/PSR7Client.php index 1ce5baed..2da53c26 100644 --- a/src/PSR7Client.php +++ b/src/PSR7Client.php @@ -31,6 +31,13 @@ class PSR7Client /*** @var UploadedFileFactoryInterface */ private $uploadsFactory; + /** @var array Valid values for HTTP protocol version */ + public static $allowedProtocolVersions = [ + '1.0', + '1.1', + '2', + ]; + /** * @param Worker $worker * @param ServerRequestFactoryInterface|null $requestFactory @@ -84,7 +91,7 @@ class PSR7Client parse_str($ctx['rawQuery'], $query); $request = $request - ->withProtocolVersion(substr($ctx['protocol'], 5)) + ->withProtocolVersion(static::normalizeHttpProtocolVersion($ctx['protocol'])) ->withCookieParams($ctx['cookies']) ->withQueryParams($query) ->withUploadedFiles($this->wrapUploads($ctx['uploads'])); @@ -181,4 +188,25 @@ class PSR7Client return $result; } + + /** + * Normalize HTTP protocol version to valid values + * @param string $version + * @return string + */ + public static function normalizeHttpProtocolVersion(string $version): string + { + $v = substr($version, 5); + + if ($v === '2.0') { + $v = '2'; + } + + // Fallback for values outside of valid protocol versions + if (!in_array($v, static::$allowedProtocolVersions, true)) { + return '1.1'; + } + + return $v; + } } |