PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.0
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.0
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / vendor_prefixed / guzzlehttp / psr7 / src / Request.php

Request.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 28.0, at vendor_prefixed/guzzlehttp/psr7/src/Request.php

140 lines 5.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare (strict_types=1);
4 namespace YoastSEO_Vendor\GuzzleHttp\Psr7;
5
6 use InvalidArgumentException;
7 use YoastSEO_Vendor\Psr\Http\Message\RequestInterface;
8 use YoastSEO_Vendor\Psr\Http\Message\StreamInterface;
9 use YoastSEO_Vendor\Psr\Http\Message\UriInterface;
10 /**
11 * PSR-7 request implementation.
12 */
13 class Request implements \YoastSEO_Vendor\Psr\Http\Message\RequestInterface
14 {
15 use MessageTrait;
16 /** @var string */
17 private $method;
18 /** @var string|null */
19 private $requestTarget;
20 /** @var UriInterface */
21 private $uri;
22 /**
23 * @param string $method HTTP method
24 * @param string|UriInterface $uri URI
25 * @param (string|string[])[] $headers Request headers
26 * @param string|resource|StreamInterface|null $body Request body
27 * @param string $version Protocol version
28 */
29 public function __construct(string $method, $uri, array $headers = [], $body = null, string $version = '1.1')
30 {
31 $this->assertMethod($method);
32 $this->assertProtocolVersion($version);
33 if (!$uri instanceof \YoastSEO_Vendor\Psr\Http\Message\UriInterface) {
34 $uri = new \YoastSEO_Vendor\GuzzleHttp\Psr7\Uri($uri);
35 }
36 self::warnOnMethodCasingChange($method);
37 $this->method = \strtoupper($method);
38 $this->uri = $uri;
39 $this->setHeaders($headers);
40 $this->protocol = $version;
41 if (!isset($this->headerNames['host'])) {
42 $this->updateHostFromUri();
43 }
44 if ($body !== '' && $body !== null) {
45 $this->stream = \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::streamFor($body);
46 }
47 }
48 public function getRequestTarget() : string
49 {
50 if ($this->requestTarget !== null) {
51 return $this->requestTarget;
52 }
53 $target = $this->uri->getPath();
54 if ($target === '') {
55 $target = '/';
56 }
57 if ($this->uri->getQuery() != '') {
58 $target .= '?' . $this->uri->getQuery();
59 }
60 return $target;
61 }
62 public function withRequestTarget($requestTarget) : \YoastSEO_Vendor\Psr\Http\Message\RequestInterface
63 {
64 if (\preg_match('#\\s#', $requestTarget)) {
65 throw new \InvalidArgumentException('Invalid request target provided; cannot contain whitespace');
66 }
67 $new = clone $this;
68 $new->requestTarget = $requestTarget;
69 return $new;
70 }
71 public function getMethod() : string
72 {
73 return $this->method;
74 }
75 public function withMethod($method) : \YoastSEO_Vendor\Psr\Http\Message\RequestInterface
76 {
77 $this->assertMethod($method);
78 self::warnOnMethodCasingChange($method);
79 $new = clone $this;
80 $new->method = \strtoupper($method);
81 return $new;
82 }
83 public function getUri() : \YoastSEO_Vendor\Psr\Http\Message\UriInterface
84 {
85 return $this->uri;
86 }
87 public function withUri(\YoastSEO_Vendor\Psr\Http\Message\UriInterface $uri, $preserveHost = \false) : \YoastSEO_Vendor\Psr\Http\Message\RequestInterface
88 {
89 if (!\is_bool($preserveHost)) {
90 \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));
91 }
92 if ($uri === $this->uri) {
93 return $this;
94 }
95 $new = clone $this;
96 $new->uri = $uri;
97 if (!$preserveHost || !isset($this->headerNames['host'])) {
98 $new->updateHostFromUri();
99 }
100 return $new;
101 }
102 private function updateHostFromUri() : void
103 {
104 $host = $this->uri->getHost();
105 if ($host == '') {
106 return;
107 }
108 \YoastSEO_Vendor\GuzzleHttp\Psr7\Uri::assertValidHost($host);
109 if (($port = $this->uri->getPort()) !== null) {
110 $host .= ':' . $port;
111 }
112 $this->assertValue($host);
113 if (isset($this->headerNames['host'])) {
114 $header = $this->headerNames['host'];
115 } else {
116 $header = 'Host';
117 $this->headerNames['host'] = 'Host';
118 }
119 // Ensure Host is the first header.
120 // See: https://datatracker.ietf.org/doc/html/rfc7230#section-5.4
121 $this->headers = [$header => [$host]] + $this->headers;
122 }
123 /**
124 * @param mixed $method
125 */
126 private function assertMethod($method) : void
127 {
128 if (!\is_string($method) || $method === '') {
129 throw new \InvalidArgumentException('Method must be a non-empty string.');
130 }
131 $this->assertNoLineSeparators($method, 'Method');
132 }
133 private static function warnOnMethodCasingChange(string $method) : void
134 {
135 if ($method !== \strtoupper($method)) {
136 \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.');
137 }
138 }
139 }
140