Skip to content

Commit

Permalink
Fix window size if body size limit is large
Browse files Browse the repository at this point in the history
Fixes #355.
  • Loading branch information
kelunik committed Sep 3, 2023
1 parent 5057e59 commit 4aabee2
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/Driver/Http2Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public function initializeWriting(
\pack(
"nNnNnNnN",
Http2Parser::INITIAL_WINDOW_SIZE,
$this->bodySizeLimit,
$this->initialWindowSize,
Http2Parser::MAX_CONCURRENT_STREAMS,
$this->concurrentStreamLimit,
Http2Parser::MAX_HEADER_LIST_SIZE,
Expand Down Expand Up @@ -727,7 +727,7 @@ private function readPreface(): string
\pack(
"nNnNnNnN",
Http2Parser::INITIAL_WINDOW_SIZE,
$this->bodySizeLimit,
$this->initialWindowSize,
Http2Parser::MAX_CONCURRENT_STREAMS,
$this->concurrentStreamLimit,
Http2Parser::MAX_HEADER_LIST_SIZE,
Expand Down Expand Up @@ -1055,9 +1055,12 @@ function (int $bodySize) use ($streamId) {
$bodySizeLimit = $this->bodySizeLimit;

if ($this->serverWindow <= $bodySizeLimit >> 1) {
$increment = $bodySizeLimit - $this->serverWindow;
$this->serverWindow = $bodySizeLimit;
$this->writeFrame(\pack("N", $increment), Http2Parser::WINDOW_UPDATE, Http2Parser::NO_FLAG);
$increment = \min($bodySizeLimit - $this->serverWindow, self::MAX_INCREMENT);

if ($increment > 0) {
$this->serverWindow += $increment;
$this->writeFrame(\pack("N", $increment), Http2Parser::WINDOW_UPDATE, Http2Parser::NO_FLAG);
}
}

if (isset($headers["content-length"])) {
Expand Down

0 comments on commit 4aabee2

Please sign in to comment.