PluginProbe
Media Cloud Sync / 1.4.1
Media Cloud Sync v1.4.1
1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 All 35 releases
← All changes | includes/sdk/s3/GuzzleHttp/PrepareBodyMiddleware.php +13 -18 1.2.4 → 1.4.1 View file →
@@ -2,32 +2,29 @@
2 2
3 3 namespace Dudlewebs\WPMCS\s3\GuzzleHttp;
4 4
5 5 use Dudlewebs\WPMCS\s3\GuzzleHttp\Promise\PromiseInterface;
6 -use Dudlewebs\WPMCS\s3\GuzzleHttp\Psr7;
7 6 use Dudlewebs\WPMCS\s3\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(RequestInterface $request, array $options)
26 + public function __invoke(RequestInterface $request, array $options) : 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 = Psr7\mimetype_from_filename($uri)) {
37 + if (\is_string($uri) && ($type = Psr7\MimeType::fromFilename($uri))) {
41 38 $modify['set_headers']['Content-Type'] = $type;
42 39 }
43 40 }
44 41 }
@@ -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(Psr7\modify_request($request, $modify), $options);
53 + return $fn(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(RequestInterface $request, array $options, array &$modify)
58 + private function addExpectHeader(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) {