PluginProbe ʕ •ᴥ•ʔ
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 25.9
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v25.9
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 19.1 19.10 19.11 19.12 19.13 19.14 19.2 19.3 19.4 19.5 19.5.1 19.6 19.6.1 19.7 19.7.1 19.7.2 19.8 19.9 20.0 20.1 20.10 20.11 20.12 20.13 20.2 20.2.1 20.3 20.4 20.5 20.6 20.7 20.8 20.9 21.0 21.1 21.2 21.3 21.4 21.5 21.6 21.7 21.8 21.8.1 21.9 21.9.1 22.0 22.1 22.2 22.3 22.4 22.5 22.6 22.7 22.8 22.9 23.0 23.1 23.2 23.3 23.4 23.5 23.6 23.7 23.8 23.9 24.0 24.1 24.2 24.3 24.4 24.5 24.6 24.7 24.8 24.8.1 24.9 25.0 25.1 25.2 25.3 25.3.1 25.4 25.5 25.6 25.7 25.8 25.9 26.0 26.1 26.1.1 26.2 26.3 26.4 26.5 26.6 26.7 26.8 26.9 27.0 27.1 27.1.1 27.2 27.3 27.4
wordpress-seo / vendor_prefixed / guzzlehttp / guzzle / src / PrepareBodyMiddleware.php
wordpress-seo / vendor_prefixed / guzzlehttp / guzzle / src Last commit date
Cookie 2 years ago Exception 2 years ago Handler 2 years ago BodySummarizer.php 2 years ago BodySummarizerInterface.php 2 years ago Client.php 2 years ago ClientInterface.php 2 years ago ClientTrait.php 2 years ago HandlerStack.php 2 years ago MessageFormatter.php 2 years ago MessageFormatterInterface.php 2 years ago Middleware.php 2 years ago Pool.php 2 years ago PrepareBodyMiddleware.php 2 years ago RedirectMiddleware.php 2 years ago RequestOptions.php 2 years ago RetryMiddleware.php 2 years ago TransferStats.php 2 years ago Utils.php 2 years ago functions.php 2 years ago functions_include.php 2 years ago
PrepareBodyMiddleware.php
87 lines
1 <?php
2
3 namespace YoastSEO_Vendor\GuzzleHttp;
4
5 use YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface;
6 use YoastSEO_Vendor\Psr\Http\Message\RequestInterface;
7 /**
8 * Prepares requests that contain a body, adding the Content-Length,
9 * Content-Type, and Expect headers.
10 *
11 * @final
12 */
13 class PrepareBodyMiddleware
14 {
15 /**
16 * @var callable(RequestInterface, array): PromiseInterface
17 */
18 private $nextHandler;
19 /**
20 * @param callable(RequestInterface, array): PromiseInterface $nextHandler Next handler to invoke.
21 */
22 public function __construct(callable $nextHandler)
23 {
24 $this->nextHandler = $nextHandler;
25 }
26 public function __invoke(\YoastSEO_Vendor\Psr\Http\Message\RequestInterface $request, array $options) : \YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface
27 {
28 $fn = $this->nextHandler;
29 // Don't do anything if the request has no body.
30 if ($request->getBody()->getSize() === 0) {
31 return $fn($request, $options);
32 }
33 $modify = [];
34 // Add a default content-type if possible.
35 if (!$request->hasHeader('Content-Type')) {
36 if ($uri = $request->getBody()->getMetadata('uri')) {
37 if (\is_string($uri) && ($type = \YoastSEO_Vendor\GuzzleHttp\Psr7\MimeType::fromFilename($uri))) {
38 $modify['set_headers']['Content-Type'] = $type;
39 }
40 }
41 }
42 // Add a default content-length or transfer-encoding header.
43 if (!$request->hasHeader('Content-Length') && !$request->hasHeader('Transfer-Encoding')) {
44 $size = $request->getBody()->getSize();
45 if ($size !== null) {
46 $modify['set_headers']['Content-Length'] = $size;
47 } else {
48 $modify['set_headers']['Transfer-Encoding'] = 'chunked';
49 }
50 }
51 // Add the expect header if needed.
52 $this->addExpectHeader($request, $options, $modify);
53 return $fn(\YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::modifyRequest($request, $modify), $options);
54 }
55 /**
56 * Add expect header
57 */
58 private function addExpectHeader(\YoastSEO_Vendor\Psr\Http\Message\RequestInterface $request, array $options, array &$modify) : void
59 {
60 // Determine if the Expect header should be used
61 if ($request->hasHeader('Expect')) {
62 return;
63 }
64 $expect = $options['expect'] ?? null;
65 // Return if disabled or if you're not using HTTP/1.1 or HTTP/2.0
66 if ($expect === \false || $request->getProtocolVersion() < 1.1) {
67 return;
68 }
69 // The expect header is unconditionally enabled
70 if ($expect === \true) {
71 $modify['set_headers']['Expect'] = '100-Continue';
72 return;
73 }
74 // By default, send the expect header when the payload is > 1mb
75 if ($expect === null) {
76 $expect = 1048576;
77 }
78 // Always add if the body cannot be rewound, the size cannot be
79 // determined, or the size is greater than the cutoff threshold
80 $body = $request->getBody();
81 $size = $body->getSize();
82 if ($size === null || $size >= (int) $expect || !$body->isSeekable()) {
83 $modify['set_headers']['Expect'] = '100-Continue';
84 }
85 }
86 }
87