PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.6
Booking for Appointments and Events Calendar – Amelia v2.4.6
2.4.7 2.4.6 2.4.5 2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / vendor / guzzlehttp / guzzle / src / PrepareBodyMiddleware.php
ameliabooking / vendor / guzzlehttp / guzzle / src Last commit date
Cookie 7 months ago Exception 7 months ago Handler 7 months ago BodySummarizer.php 7 months ago BodySummarizerInterface.php 7 months ago Client.php 7 months ago ClientInterface.php 7 months ago ClientTrait.php 7 months ago HandlerStack.php 7 months ago MessageFormatter.php 7 months ago MessageFormatterInterface.php 7 months ago Middleware.php 7 months ago Pool.php 7 months ago PrepareBodyMiddleware.php 7 months ago RedirectMiddleware.php 7 months ago RequestOptions.php 7 months ago RetryMiddleware.php 7 months ago TransferStats.php 7 months ago Utils.php 7 months ago functions.php 7 months ago functions_include.php 7 months ago
PrepareBodyMiddleware.php
86 lines
1 <?php
2
3 namespace AmeliaVendor\GuzzleHttp;
4
5 use AmeliaVendor\GuzzleHttp\Promise\PromiseInterface;
6 use AmeliaVendor\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(RequestInterface $request, array $options): 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 = \AmeliaVendor\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(\AmeliaVendor\GuzzleHttp\Psr7\Utils::modifyRequest($request, $modify), $options);
54 }
55 /**
56 * Add expect header
57 */
58 private function addExpectHeader(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 using HTTP/1.0
66 if ($expect === false || $request->getProtocolVersion() === '1.0') {
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 }