diff options
author | bof09595 <[email protected]> | 2018-12-20 10:49:57 +0100 |
---|---|---|
committer | bof09595 <[email protected]> | 2018-12-20 10:49:57 +0100 |
commit | 2f87aa2741102641c62b62b1d7e3b184d4b8e17c (patch) | |
tree | 10c199bed79409b9a115eb58f0c6bdf55b20c814 /src/PSR7Client.php | |
parent | aaabf08f9d124d45b65b6efd3fa3146e1cb42f93 (diff) |
#67 Unsupported HTTP protocol version "2.0"
Normalizing protocol version strings to match official values 1.0, 1.1 and 2
Diffstat (limited to 'src/PSR7Client.php')
-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; + } } |