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/Aws/RequestCompressionMiddleware.php +8 -2 1.2.131.4.1 View file →
@@ -42,14 +42,16 @@
42 42 $this->minimumCompressionSize = $command['@request_min_compression_size_bytes'];
43 43 }
44 44 $nextHandler = $this->nextHandler;
45 45 $operation = $this->api->getOperation($command->getName());
46 - $compressionInfo = isset($operation['requestcompression']) ? $operation['requestcompression'] : null;
46 + $compressionInfo = $operation['requestcompression'] ?? null;
47 47 if (!$this->shouldCompressRequestBody($compressionInfo, $command, $operation, $request)) {
48 48 return $nextHandler($command, $request);
49 49 }
50 50 $this->encodings = $compressionInfo['encodings'];
51 51 $request = $this->compressRequestBody($request);
52 + // Capture request compression metric
53 + $command->getMetricsBuilder()->identifyMetricByValueAndAppend('request_compression', $request->getHeaderLine('content-encoding'));
52 54 return $nextHandler($command, $request);
53 55 }
54 56 private function compressRequestBody(RequestInterface $request)
55 57 {
@@ -58,9 +60,13 @@
58 60 return $request;
59 61 }
60 62 $body = $request->getBody()->getContents();
61 63 $compressedBody = $fn($body);
62 - return $request->withBody(Psr7\Utils::streamFor($compressedBody))->withHeader('content-encoding', $this->encoding);
64 + $request = $request->withBody(Psr7\Utils::streamFor($compressedBody));
65 + if ($request->hasHeader('Content-Encoding')) {
66 + return $request->withAddedHeader('Content-Encoding', $this->encoding);
67 + }
68 + return $request->withHeader('Content-Encoding', $this->encoding);
63 69 }
64 70 private function determineEncoding()
65 71 {
66 72 foreach ($this->encodings as $encoding) {