Skip to content

Commit

Permalink
Ignore TE request header on HTTP/2
Browse files Browse the repository at this point in the history
  • Loading branch information
kelunik committed Jul 12, 2021
1 parent ec4defd commit fafc7a0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Connection/Internal/Http2ConnectionProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -1698,6 +1698,10 @@ private function generateHeaders(Request $request): array

foreach ($request->getHeaders() as $field => $values) {
foreach ($values as $value) {
if ($field === 'te' && $value !== 'trailers') {
continue;
}

$headers[] = [$field, $value];
}
}
Expand Down
23 changes: 22 additions & 1 deletion test/ClientHttpBinIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Amp\Http\Cookie\RequestCookie;
use Amp\Http\Cookie\ResponseCookie;
use Amp\Http\Rfc7230;
use Amp\Http\Server\Options;
use Amp\Http\Server\Request as ServerRequest;
use Amp\Http\Server\RequestHandler\CallableRequestHandler;
use Amp\Http\Server\Response as ServerResponse;
Expand Down Expand Up @@ -369,6 +370,26 @@ public function testReason(): \Generator
$this->assertSame($expectedReason, $actualReason);
}

public function testHttp2TeHeader(): \Generator
{
$this->client = $this->builder->followRedirects(0)->build();

$this->givenServer(static function () {
return new ServerResponse(200);
});

$request = $this->createRequest();
$request->setProtocolVersions(['2']);
$request->setHeader('te', 'gzip');

/** @var Response $response */
$response = yield $this->executeRequest($request);

$this->assertInstanceOf(Response::class, $response);
$this->assertSame(200, $response->getStatus());
$this->assertSame($response, $response->getOriginalResponse());
}

public function testRedirect(): \Generator
{
$this->client = $this->builder->followRedirects(0)->build();
Expand Down Expand Up @@ -802,7 +823,7 @@ protected function setUp(): void

private function givenServer(callable $requestHandler): void
{
$this->httpServer = new Server([$this->socket], new CallableRequestHandler($requestHandler), new NullLogger);
$this->httpServer = new Server([$this->socket], new CallableRequestHandler($requestHandler), new NullLogger, (new Options)->withHttp2Upgrade());
$this->httpServer->start();
}

Expand Down

0 comments on commit fafc7a0

Please sign in to comment.