Skip to content

Commit

Permalink
Fix non-empty END_STREAM message being discarded
Browse files Browse the repository at this point in the history
  • Loading branch information
bwoebi committed Jul 18, 2017
1 parent 7735040 commit aac7026
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
22 changes: 10 additions & 12 deletions lib/Http2Driver.php
Expand Up @@ -535,23 +535,21 @@ public function parser(Client $client, $settings = ""): \Generator {
$buffer .= yield;
}

if (($flags & self::END_STREAM) !== "\0") {
unset($bodyLens[$id], $client->streamWindow[$id]);
$type = HttpDriver::ENTITY_PART;
} else {
$bodyLens[$id] += $length;
$type = HttpDriver::ENTITY_RESULT;
}

$body = \substr($buffer, 0, $length - $padding);
assert(!\defined("Aerys\\DEBUG_HTTP2") || print "DATA($length): $body\n");
$buffer = \substr($buffer, $length);
if ($body != "") {
($this->emit)($client, $type, ["id" => $id, "protocol" => "2.0", "body" => $body], null);
($this->emit)($client, HttpDriver::ENTITY_PART, ["id" => $id, "body" => $body], null);
}
$buffer = \substr($buffer, $length);

if ($remaining == 0 && ($flags & self::END_STREAM) !== "\0" && $length) {
($this->emit)($client, HttpDriver::SIZE_WARNING, ["id" => $id], null);
if (($flags & self::END_STREAM) !== "\0") {
unset($bodyLens[$id], $client->streamWindow[$id]);
($this->emit)($client, HttpDriver::ENTITY_RESULT, ["id" => $id], null);
} else {
$bodyLens[$id] += $length;
if ($remaining == 0 && $length) {
($this->emit)($client, HttpDriver::SIZE_WARNING, ["id" => $id], null);
}
}

continue 2;
Expand Down
4 changes: 2 additions & 2 deletions test/Http2DriverTest.php
Expand Up @@ -56,7 +56,7 @@ protected function writeFrame(Client $client, $data, $type, $flags, $stream = 0)
$parseResult = $tmpResult;
}
$this->assertNull($errorStruct);
$body .= $tmpResult["body"];
$body .= $tmpResult["body"] ?? "";
$client->bodyPromisors[$tmpResult["id"]] = true; // is used to verify whether headers were sent
};
$driver->setup($emitCallback, function(){});
Expand Down Expand Up @@ -131,7 +131,7 @@ function provideSimpleCases() {
"uri" => "http://localhost/",
"headers" => ["test" => ["successful"]],
"body" => "ab",
"invocations" => 3
"invocations" => 4 /* header + 2 * individual data + end */
];

$return[] = [$msg, $expectations];
Expand Down

0 comments on commit aac7026

Please sign in to comment.