| @@ -28,12 +28,14 @@ | ||
| 28 | 28 | */ |
| 29 | 29 | public function __construct(string $method, $uri, array $headers = [], $body = null, string $version = '1.1') |
| 30 | 30 | { |
| 31 | 31 | $this->assertMethod($method); |
| 32 | + $this->assertProtocolVersion($version); | |
| 32 | 33 | if (!$uri instanceof \YoastSEO_Vendor\Psr\Http\Message\UriInterface) { |
| 33 | 34 | $uri = new \YoastSEO_Vendor\GuzzleHttp\Psr7\Uri($uri); |
| 34 | 35 | } |
| 35 | - $this->method = \strtoupper($method); | |
| 36 | + self::warnOnMethodCasingChange($method); | |
| 37 | + $this->method = \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::asciiToUpper($method); | |
| 36 | 38 | $this->uri = $uri; |
| 37 | 39 | $this->setHeaders($headers); |
| 38 | 40 | $this->protocol = $version; |
| 39 | 41 | if (!isset($this->headerNames['host'])) { |
| @@ -58,9 +60,13 @@ | ||
| 58 | 60 | return $target; |
| 59 | 61 | } |
| 60 | 62 | public function withRequestTarget($requestTarget) : \YoastSEO_Vendor\Psr\Http\Message\RequestInterface |
| 61 | 63 | { |
| 62 | - if (\preg_match('#\\s#', $requestTarget)) { | |
| 64 | + $hasWhitespace = \preg_match('#\\s#', $requestTarget); | |
| 65 | + if ($hasWhitespace === \false) { | |
| 66 | + throw new \RuntimeException('Unable to validate request target: ' . \preg_last_error_msg()); | |
| 67 | + } | |
| 68 | + if ($hasWhitespace === 1) { | |
| 63 | 69 | throw new \InvalidArgumentException('Invalid request target provided; cannot contain whitespace'); |
| 64 | 70 | } |
| 65 | 71 | $new = clone $this; |
| 66 | 72 | $new->requestTarget = $requestTarget; |
| @@ -72,10 +78,11 @@ | ||
| 72 | 78 | } |
| 73 | 79 | public function withMethod($method) : \YoastSEO_Vendor\Psr\Http\Message\RequestInterface |
| 74 | 80 | { |
| 75 | 81 | $this->assertMethod($method); |
| 82 | + self::warnOnMethodCasingChange($method); | |
| 76 | 83 | $new = clone $this; |
| 77 | - $new->method = \strtoupper($method); | |
| 84 | + $new->method = \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::asciiToUpper($method); | |
| 78 | 85 | return $new; |
| 79 | 86 | } |
| 80 | 87 | public function getUri() : \YoastSEO_Vendor\Psr\Http\Message\UriInterface |
| 81 | 88 | { |
| @@ -82,8 +89,11 @@ | ||
| 82 | 89 | return $this->uri; |
| 83 | 90 | } |
| 84 | 91 | public function withUri(\YoastSEO_Vendor\Psr\Http\Message\UriInterface $uri, $preserveHost = \false) : \YoastSEO_Vendor\Psr\Http\Message\RequestInterface |
| 85 | 92 | { |
| 93 | + if (!\is_bool($preserveHost)) { | |
| 94 | + \YoastSEO_Vendor\trigger_deprecation('guzzlehttp/psr7', '2.11', 'Passing %s to RequestInterface::withUri() is deprecated; guzzlehttp/psr7 3.0 requires bool for $preserveHost.', \get_debug_type($preserveHost)); | |
| 95 | + } | |
| 86 | 96 | if ($uri === $this->uri) { |
| 87 | 97 | return $this; |
| 88 | 98 | } |
| 89 | 99 | $new = clone $this; |
| @@ -98,11 +108,13 @@ | ||
| 98 | 108 | $host = $this->uri->getHost(); |
| 99 | 109 | if ($host == '') { |
| 100 | 110 | return; |
| 101 | 111 | } |
| 112 | + \YoastSEO_Vendor\GuzzleHttp\Psr7\Uri::assertValidHost($host); | |
| 102 | 113 | if (($port = $this->uri->getPort()) !== null) { |
| 103 | 114 | $host .= ':' . $port; |
| 104 | 115 | } |
| 116 | + $this->assertValue($host); | |
| 105 | 117 | if (isset($this->headerNames['host'])) { |
| 106 | 118 | $header = $this->headerNames['host']; |
| 107 | 119 | } else { |
| 108 | 120 | $header = 'Host'; |
| @@ -118,7 +130,14 @@ | ||
| 118 | 130 | private function assertMethod($method) : void |
| 119 | 131 | { |
| 120 | 132 | if (!\is_string($method) || $method === '') { |
| 121 | 133 | throw new \InvalidArgumentException('Method must be a non-empty string.'); |
| 134 | + } | |
| 135 | + $this->assertNoLineSeparators($method, 'Method'); | |
| 136 | + } | |
| 137 | + private static function warnOnMethodCasingChange(string $method) : void | |
| 138 | + { | |
| 139 | + if ($method !== \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::asciiToUpper($method)) { | |
| 140 | + \YoastSEO_Vendor\trigger_deprecation('guzzlehttp/psr7', '2.11', 'Passing a non-uppercase HTTP method is deprecated; guzzlehttp/psr7 3.0 preserves method casing and will no longer uppercase it. Normalize the method before constructing or modifying requests if uppercase is required.'); | |
| 122 | 141 | } |
| 123 | 142 | } |
| 124 | 143 | } |