| @@ -139,9 +139,9 @@ | ||
| 139 | 139 | public function sendAsync(\YoastSEO_Vendor\Psr\Http\Message\RequestInterface $request, array $options = []) : \YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface |
| 140 | 140 | { |
| 141 | 141 | // Merge the base URI into the request URI if needed. |
| 142 | 142 | $options = $this->prepareDefaults($options); |
| 143 | - return $this->transfer($request->withUri($this->buildUri($request->getUri(), $options), $request->hasHeader('Host')), $options); | |
| 143 | + return $this->transfer($request->withUri($this->buildUri($request->getUri(), $options), self::shouldPreserveHost($request)), $options); | |
| 144 | 144 | } |
| 145 | 145 | /** |
| 146 | 146 | * Send an HTTP request. |
| 147 | 147 | * |
| @@ -256,8 +256,28 @@ | ||
| 256 | 256 | if ($uri->getScheme() === '' && $uri->getHost() !== '') { |
| 257 | 257 | $uri = $uri->withScheme('http'); |
| 258 | 258 | } |
| 259 | 259 | return $uri; |
| 260 | + } | |
| 261 | + /** | |
| 262 | + * Whether to preserve an existing Host header when the URI changes. | |
| 263 | + * | |
| 264 | + * A header matching the current URI carries no explicit override and is | |
| 265 | + * regenerated after base URI resolution or IDN conversion. Other values | |
| 266 | + * are preserved as deliberate overrides, as PSR-7 requires. | |
| 267 | + */ | |
| 268 | + private static function shouldPreserveHost(\YoastSEO_Vendor\Psr\Http\Message\RequestInterface $request) : bool | |
| 269 | + { | |
| 270 | + if (!$request->hasHeader('Host')) { | |
| 271 | + return \false; | |
| 272 | + } | |
| 273 | + $uri = $request->getUri(); | |
| 274 | + $host = $uri->getHost(); | |
| 275 | + $port = $uri->getPort(); | |
| 276 | + if ($port !== null) { | |
| 277 | + $host .= ':' . $port; | |
| 278 | + } | |
| 279 | + return $host !== $request->getHeaderLine('Host'); | |
| 260 | 280 | } |
| 261 | 281 | /** |
| 262 | 282 | * Configures the default options for a client. |
| 263 | 283 | */ |