Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Driver/Http2Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,8 @@ function (int $bodySize) use ($streamId) {

public function handleData(int $streamId, string $data): void
{
$this->pinged = 0;

$length = \strlen($data);

if ($streamId & 1) {
Expand Down
34 changes: 34 additions & 0 deletions test/Driver/Http2DriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,40 @@ public function testPingFlood(): void
);
}

public function testIncomingDataResetsPingFloodProtection(): void
{
$buffer = Http2Parser::PREFACE;
$buffer .= self::packHeader([
':authority' => 'localhost',
':path' => '/',
':scheme' => 'http',
':method' => 'POST',
], true);

$ping = "aaaaaaaa";
for ($i = 0; $i < 10; ++$i) {
$buffer .= self::packFrame($ping++, Http2Parser::PING, Http2Parser::NO_FLAG);
$buffer .= self::packFrame('a', Http2Parser::DATA, Http2Parser::NO_FLAG, 1);
}

$buffer .= self::packFrame('', Http2Parser::DATA, Http2Parser::END_STREAM, 1);

$this->givenInput(new ReadableBuffer($buffer));

$this->whenClientIsHandled();

$output = \bin2hex(buffer($this->output->getSource()));

self::assertStringNotContainsString(
\bin2hex(\pack("NN", 0, Http2Parser::ENHANCE_YOUR_CALM) . 'Too many pings'),
$output
);
self::assertStringContainsString(
\bin2hex(self::packFrame('aaaaaaaa', Http2Parser::PING, Http2Parser::ACK)),
$output
);
}

public function testSendingResponseBeforeRequestCompletes(): void
{
$headers = [
Expand Down
Loading