PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 27.5
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v27.5
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 27.5, at vendor_prefixed/guzzlehttp/psr7/src/Request.php

125 lines 4.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 if (!$uri instanceof \YoastSEO_Vendor\Psr\Http\Message\UriInterface) {
33 $uri = new \YoastSEO_Vendor\GuzzleHttp\Psr7\Uri($uri);
34 }
35 $this->method = \strtoupper($method);
36 $this->uri = $uri;
37 $this->setHeaders($headers);
38 $this->protocol = $version;
39 if (!isset($this->headerNames['host'])) {
40 $this->updateHostFromUri();
41 }
42 if ($body !== '' && $body !== null) {
43 $this->stream = \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::streamFor($body);
44 }
45 }
46 public function getRequestTarget() : string
47 {
48 if ($this->requestTarget !== null) {
49 return $this->requestTarget;
50 }
51 $target = $this->uri->getPath();
52 if ($target === '') {
53 $target = '/';
54 }
55 if ($this->uri->getQuery() != '') {
56 $target .= '?' . $this->uri->getQuery();
57 }
58 return $target;
59 }
60 public function withRequestTarget($requestTarget) : \YoastSEO_Vendor\Psr\Http\Message\RequestInterface
61 {
62 if (\preg_match('#\\s#', $requestTarget)) {
63 throw new \InvalidArgumentException('Invalid request target provided; cannot contain whitespace');
64 }
65 $new = clone $this;
66 $new->requestTarget = $requestTarget;
67 return $new;
68 }
69 public function getMethod() : string
70 {
71 return $this->method;
72 }
73 public function withMethod($method) : \YoastSEO_Vendor\Psr\Http\Message\RequestInterface
74 {
75 $this->assertMethod($method);
76 $new = clone $this;
77 $new->method = \strtoupper($method);
78 return $new;
79 }
80 public function getUri() : \YoastSEO_Vendor\Psr\Http\Message\UriInterface
81 {
82 return $this->uri;
83 }
84 public function withUri(\YoastSEO_Vendor\Psr\Http\Message\UriInterface $uri, $preserveHost = \false) : \YoastSEO_Vendor\Psr\Http\Message\RequestInterface
85 {
86 if ($uri === $this->uri) {
87 return $this;
88 }
89 $new = clone $this;
90 $new->uri = $uri;
91 if (!$preserveHost || !isset($this->headerNames['host'])) {
92 $new->updateHostFromUri();
93 }
94 return $new;
95 }
96 private function updateHostFromUri() : void
97 {
98 $host = $this->uri->getHost();
99 if ($host == '') {
100 return;
101 }
102 if (($port = $this->uri->getPort()) !== null) {
103 $host .= ':' . $port;
104 }
105 if (isset($this->headerNames['host'])) {
106 $header = $this->headerNames['host'];
107 } else {
108 $header = 'Host';
109 $this->headerNames['host'] = 'Host';
110 }
111 // Ensure Host is the first header.
112 // See: https://datatracker.ietf.org/doc/html/rfc7230#section-5.4
113 $this->headers = [$header => [$host]] + $this->headers;
114 }
115 /**
116 * @param mixed $method
117 */
118 private function assertMethod($method) : void
119 {
120 if (!\is_string($method) || $method === '') {
121 throw new \InvalidArgumentException('Method must be a non-empty string.');
122 }
123 }
124 }
125