react-http2/tests/Http2MiddlewareTest.php

51 lines
1.4 KiB
PHP
Raw Normal View History

<?php
namespace NoccyLabs\React\Http2;
use NoccyLabs\React\Http2\Frame\SettingsFrame;
use PHPUnit\Framework\Attributes\CoversClass;
use Psr\Http\Message\ResponseInterface;
use React\Http\Message\Response;
use React\Http\Message\ServerRequest;
#[CoversClass(Http2Middleware::class)]
class Http2MiddlewareTest extends \PHPUnit\Framework\TestCase
{
public function testInvalidUpgradeRequests()
{
$request = new ServerRequest("GET", "/", [
"Upgrade" => "h2",
"x-forwarded-proto" => "http"
]);
$middleware = new Http2Middleware();
/** @var ResponseInterface $response */
$response = $middleware($request);
$this->assertEquals(Response::STATUS_BAD_REQUEST, $response->getStatusCode());
}
public function testHandlingUpgradeRequest()
{
$http2settings = new SettingsFrame();
$http2settings->set(SettingsFrame::SETTINGS_MAX_CONCURRENT_STREAMS, 64);
$request = new ServerRequest("GET", "/", [
"Upgrade" => "h2c",
"Connection" => "upgrade",
"x-forwarded-proto" => "http",
"HTTP2-Settings" => $http2settings->toBinary(),
]);
$middleware = new Http2Middleware();
/** @var ResponseInterface $response */
$response = $middleware($request);
$this->assertEquals(Response::STATUS_SWITCHING_PROTOCOLS, $response->getStatusCode());
}
}