PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / trunk
Yoast SEO – Advanced SEO with real-time guidance and built-in AI vtrunk
28.6 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 All 130 releases
← All changes | vendor_prefixed/guzzlehttp/guzzle/src/PrepareBodyMiddleware.php +14 -19 18.4.1 → trunk View file →
@@ -2,32 +2,29 @@
2 2
3 3 namespace YoastSEO_Vendor\GuzzleHttp;
4 4
5 5 use YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface;
6 -use YoastSEO_Vendor\GuzzleHttp\Psr7;
7 6 use YoastSEO_Vendor\Psr\Http\Message\RequestInterface;
8 7 /**
9 8 * Prepares requests that contain a body, adding the Content-Length,
10 9 * Content-Type, and Expect headers.
10 + *
11 + * @final
11 12 */
12 13 class PrepareBodyMiddleware
13 14 {
14 - /** @var callable */
15 + /**
16 + * @var callable(RequestInterface, array): PromiseInterface
17 + */
15 18 private $nextHandler;
16 19 /**
17 - * @param callable $nextHandler Next handler to invoke.
20 + * @param callable(RequestInterface, array): PromiseInterface $nextHandler Next handler to invoke.
18 21 */
19 22 public function __construct(callable $nextHandler)
20 23 {
21 24 $this->nextHandler = $nextHandler;
22 25 }
23 - /**
24 - * @param RequestInterface $request
25 - * @param array $options
26 - *
27 - * @return PromiseInterface
28 - */
29 - public function __invoke(\YoastSEO_Vendor\Psr\Http\Message\RequestInterface $request, array $options)
26 + public function __invoke(\YoastSEO_Vendor\Psr\Http\Message\RequestInterface $request, array $options) : \YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface
30 27 {
31 28 $fn = $this->nextHandler;
32 29 // Don't do anything if the request has no body.
33 30 if ($request->getBody()->getSize() === 0) {
@@ -36,9 +33,9 @@
36 33 $modify = [];
37 34 // Add a default content-type if possible.
38 35 if (!$request->hasHeader('Content-Type')) {
39 36 if ($uri = $request->getBody()->getMetadata('uri')) {
40 - if ($type = \YoastSEO_Vendor\GuzzleHttp\Psr7\mimetype_from_filename($uri)) {
37 + if (\is_string($uri) && ($type = \YoastSEO_Vendor\GuzzleHttp\Psr7\MimeType::fromFilename($uri))) {
41 38 $modify['set_headers']['Content-Type'] = $type;
42 39 }
43 40 }
44 41 }
@@ -45,9 +42,9 @@
45 42 // Add a default content-length or transfer-encoding header.
46 43 if (!$request->hasHeader('Content-Length') && !$request->hasHeader('Transfer-Encoding')) {
47 44 $size = $request->getBody()->getSize();
48 45 if ($size !== null) {
49 - $modify['set_headers']['Content-Length'] = $size;
46 + $modify['set_headers']['Content-Length'] = (string) $size;
50 47 } else {
51 48 $modify['set_headers']['Transfer-Encoding'] = 'chunked';
52 49 }
53 50 }
@@ -52,24 +49,22 @@
52 49 }
53 50 }
54 51 // Add the expect header if needed.
55 52 $this->addExpectHeader($request, $options, $modify);
56 - return $fn(\YoastSEO_Vendor\GuzzleHttp\Psr7\modify_request($request, $modify), $options);
53 + return $fn(\YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::modifyRequest($request, $modify), $options);
57 54 }
58 55 /**
59 56 * Add expect header
60 - *
61 - * @return void
62 57 */
63 - private function addExpectHeader(\YoastSEO_Vendor\Psr\Http\Message\RequestInterface $request, array $options, array &$modify)
58 + private function addExpectHeader(\YoastSEO_Vendor\Psr\Http\Message\RequestInterface $request, array $options, array &$modify) : void
64 59 {
65 60 // Determine if the Expect header should be used
66 61 if ($request->hasHeader('Expect')) {
67 62 return;
68 63 }
69 - $expect = isset($options['expect']) ? $options['expect'] : null;
70 - // Return if disabled or if you're not using HTTP/1.1 or HTTP/2.0
71 - if ($expect === \false || $request->getProtocolVersion() < 1.1) {
64 + $expect = $options['expect'] ?? null;
65 + // Return if disabled or using HTTP/1.0
66 + if ($expect === \false || $request->getProtocolVersion() === '1.0') {
72 67 return;
73 68 }
74 69 // The expect header is unconditionally enabled
75 70 if ($expect === \true) {