PluginProbe
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript / 4.1.20
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript v4.1.20
4.1.20 4.1.19 4.1.18 4.1.17 4.1.16 4.1.15 4.1.14 4.1.13 4.1.12 4.1.11 4.1.10 4.0.30 4.0.29 4.0.28 4.0.27 4.0.26 4.0.24 4.0.25 4.0.23 4.0.22 4.0.21 4.0.19 4.0.18 4.0.17 4.0.16 All 174 releases
searchpro / BerqWP / vendor-prefixed / vendor / guzzlehttp / psr7 / src / Request.php

Request.php in BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript 4.1.20, at BerqWP/vendor-prefixed/vendor/guzzlehttp/psr7/src/Request.php

125 lines 3.8 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 BerqWP_Deps\GuzzleHttp\Psr7;
5
6 use InvalidArgumentException;
7 use BerqWP_Deps\Psr\Http\Message\RequestInterface;
8 use BerqWP_Deps\Psr\Http\Message\StreamInterface;
9 use BerqWP_Deps\Psr\Http\Message\UriInterface;
10 /**
11 * PSR-7 request implementation.
12 */
13 class Request implements 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 UriInterface) {
33 $uri = new 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 = 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): 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): RequestInterface
74 {
75 $this->assertMethod($method);
76 $new = clone $this;
77 $new->method = strtoupper($method);
78 return $new;
79 }
80 public function getUri(): UriInterface
81 {
82 return $this->uri;
83 }
84 public function withUri(UriInterface $uri, $preserveHost = \false): 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