diff --git a/src/Driver/Http2Driver.php b/src/Driver/Http2Driver.php index 813056b2..5b1acec2 100644 --- a/src/Driver/Http2Driver.php +++ b/src/Driver/Http2Driver.php @@ -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) { diff --git a/test/Driver/Http2DriverTest.php b/test/Driver/Http2DriverTest.php index 4f573fb3..ee32c2b9 100644 --- a/test/Driver/Http2DriverTest.php +++ b/test/Driver/Http2DriverTest.php @@ -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 = [