Skip to content

Commit

Permalink
enhancement: update compression size logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean O'Brien committed Aug 3, 2023
1 parent dc082f3 commit bfe01b9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Empty file.
16 changes: 12 additions & 4 deletions src/RequestCompressionMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __invoke(CommandInterface $command, RequestInterface $request)
}
$nextHandler = $this->nextHandler;
$operation = $this->api->getOperation($command->getName());
$requestBodySize = $request->getBody()->getSize();
// $requestBodySize = $request->getBody()->getSize();
$compressionInfo = isset($operation['requestcompression'])
? $operation['requestcompression']
: null;
Expand All @@ -60,7 +60,7 @@ public function __invoke(CommandInterface $command, RequestInterface $request)
$compressionInfo,
$command,
$operation,
$requestBodySize
$request
)) {
return $nextHandler($command, $request);
}
Expand Down Expand Up @@ -101,18 +101,26 @@ private function shouldCompressRequestBody(
$compressionInfo,
$command,
$operation,
$requestBodySize
$request
){
if ($compressionInfo) {
if (isset($command['@disable_request_compression'])
&& $command['@disable_request_compression'] === true
) {
return false;
} elseif ($this->hasStreamingTraitWithoutRequiresLength($command, $operation)
|| $requestBodySize >= $this->minimumCompressionSize
) {
return true;
}

$hasContentLength = $request->hasHeader('content-length');
$requestBodySize = $hasContentLength
? (int) $request->getHeaderLine('content-length')
: $request->getBody()->getSize();

if ($requestBodySize >= $this->minimumCompressionSize) {
return true;
}
}
return false;
}
Expand Down

0 comments on commit bfe01b9

Please sign in to comment.