Skip to content

Commit

Permalink
Merge branch 'v1.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Jan 4, 2020
2 parents ac67815 + b1d83bc commit 2c3d572
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
10 changes: 4 additions & 6 deletions src/Driver/Http1Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -729,16 +729,14 @@ function (int $bodySize) use (&$maxBodySize) {
if ($bufferLength >= $chunkLengthRemaining + 2) {
yield $emitter->emit(\substr($buffer, 0, $chunkLengthRemaining));
$buffer = \substr($buffer, $chunkLengthRemaining + 2);
} else {
yield $emitter->emit($buffer);
$buffer = "";
$chunkLengthRemaining -= $bufferLength;
}

if ($bufferLength >= $chunkLengthRemaining + 2) {
$chunkLengthRemaining = null;
continue 2; // next chunk (chunked loop)
}

yield $emitter->emit($buffer);
$buffer = "";
$chunkLengthRemaining -= $bufferLength;
}
}

Expand Down
22 changes: 18 additions & 4 deletions test/Driver/Http1DriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,21 @@ public function testIdentityBodyParseEmit(): \Generator
$this->assertSame($originalBody, $body);
}

public function testChunkedBodyParseEmit(): \Generator
/**
* provide multiple chunk-sizes to test with.
* @return \Generator
*/
public function chunkSizeProvider(): \Generator
{
for ($i = 1; $i < 11; $i++) {
yield [$i];
}
}

/**
* @dataProvider chunkSizeProvider
*/
public function testChunkedBodyParseEmit(int $chunkSize): \Generator
{
$msg =
"POST https://test.local:1337/post-endpoint HTTP/1.0\r\n" .
Expand Down Expand Up @@ -251,10 +265,10 @@ public function testChunkedBodyParseEmit(): \Generator
$this->createCallback(0)
);

for ($i = 0, $c = \strlen($msg); $i < $c; $i++) {
$promise = $parser->send($msg[$i]);
foreach (\str_split($msg, $chunkSize) as $chunk) {
$promise = $parser->send($chunk);
while ($promise instanceof Promise) {
$promise = $parser->send(null);
$promise = $parser->send("");
}
}

Expand Down

0 comments on commit 2c3d572

Please sign in to comment.