Skip to content

Commit

Permalink
Simplify SizeLimitingInputStream
Browse files Browse the repository at this point in the history
  • Loading branch information
kelunik committed Nov 8, 2019
1 parent 14302ed commit c8777ca
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/Internal/SizeLimitingInputStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,15 @@ public function read(): Promise

$promise = $this->source->read();
$promise->onResolve(function ($error, $value) {
if ($error === null) {
if ($value !== null) {
$this->bytesRead += \strlen($value);
if ($this->bytesRead > $this->sizeLimit) {
$this->exception = new ParseException(
"Configured body size exceeded: {$this->bytesRead} bytes received, while the configured limit is {$this->sizeLimit} bytes",
Status::PAYLOAD_TOO_LARGE
);

$this->source = null;
}
if ($value !== null) {
$this->bytesRead += \strlen($value);
if ($this->bytesRead > $this->sizeLimit) {
$this->exception = new ParseException(
"Configured body size exceeded: {$this->bytesRead} bytes received, while the configured limit is {$this->sizeLimit} bytes",
Status::PAYLOAD_TOO_LARGE
);

$this->source = null;
}
}
});
Expand Down

0 comments on commit c8777ca

Please sign in to comment.