Skip to content

Commit

Permalink
Declare protocol as "2", not "2.0"
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Sep 7, 2019
1 parent dc038c9 commit 9f136fb
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/Connection/DefaultConnectionPool.php
Expand Up @@ -21,7 +21,7 @@

final class DefaultConnectionPool implements ConnectionPool
{
private const PROTOCOL_VERSIONS = ['1.0', '1.1', '2.0'];
private const PROTOCOL_VERSIONS = ['1.0', '1.1', '2'];

/** @var Connector */
private $connector;
Expand Down Expand Up @@ -85,7 +85,7 @@ public function getStream(Request $request, CancellationToken $cancellation): Pr
$connectContext = $this->connectContext;

if ($isHttps) {
if (\in_array('2.0', $request->getProtocolVersions(), true)) {
if (\in_array('2', $request->getProtocolVersions(), true)) {
$protocols = ['h2', 'http/1.1'];
} else {
$protocols = ['http/1.1'];
Expand Down
8 changes: 4 additions & 4 deletions src/Connection/Http2Connection.php
Expand Up @@ -35,7 +35,7 @@

final class Http2Connection implements Connection
{
private const PROTOCOL_VERSIONS = ['2.0'];
private const PROTOCOL_VERSIONS = ['2'];

public const PREFACE = "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n";
public const DEFAULT_MAX_FRAME_SIZE = 1 << 14;
Expand Down Expand Up @@ -1116,7 +1116,7 @@ private function parser(): \Generator

$stream->request = new Request($uri, $method);
$stream->request->setHeaders($headers);
$stream->request->setProtocolVersions(['2.0']);
$stream->request->setProtocolVersions(['2']);
$stream->request->onPush($stream->parent->request->getPushCallable());

$this->pendingRequests[$id] = $deferred = new Deferred;
Expand Down Expand Up @@ -1199,7 +1199,7 @@ private function parser(): \Generator

if ($stream->state & Http2Stream::REMOTE_CLOSED) {
$response = new Response(
"2.0",
'2',
$status,
Status::getReason($status),
$headers,
Expand Down Expand Up @@ -1240,7 +1240,7 @@ private function parser(): \Generator
});

$response = new Response(
"2.0",
'2',
$status,
Status::getReason($status),
$headers,
Expand Down
4 changes: 2 additions & 2 deletions src/Request.php
Expand Up @@ -16,7 +16,7 @@ final class Request extends Message
public const DEFAULT_BODY_SIZE_LIMIT = 10485760;

/** @var string[] */
private $protocolVersions = ["1.1", "2.0"];
private $protocolVersions = ['1.1', '2'];

/** @var string */
private $method;
Expand Down Expand Up @@ -85,7 +85,7 @@ public function setProtocolVersions(array $versions): void
}

foreach ($versions as $version) {
if (!\in_array($version, ["1.0", "1.1", "2.0"], true)) {
if (!\in_array($version, ["1.0", "1.1", "2"], true)) {
/** @noinspection PhpUndefinedClassInspection */
throw new \Error(
"Invalid HTTP protocol version: " . $version
Expand Down
4 changes: 2 additions & 2 deletions test/RequestTest.php
Expand Up @@ -44,8 +44,8 @@ public function testProtocolVersionsAcceptsValidInput(): void
$this->assertSame(["1.0"], $request->getProtocolVersions());

$request = new Request("http://127.0.0.1/");
$request->setProtocolVersions(["1.0", "2.0"]);
$this->assertSame(["1.0", "2.0"], $request->getProtocolVersions());
$request->setProtocolVersions(["1.0", "2"]);
$this->assertSame(["1.0", "2"], $request->getProtocolVersions());
}

public function testHeader(): void
Expand Down
4 changes: 2 additions & 2 deletions test/ResponseTest.php
Expand Up @@ -10,9 +10,9 @@ class ResponseTest extends TestCase
public function testProtocolVersion(): void
{
$response = $this->createResponse();
$response->setProtocolVersion('2.0');
$response->setProtocolVersion('2');

$this->assertSame('2.0', $response->getProtocolVersion());
$this->assertSame('2', $response->getProtocolVersion());
}

public function testStatus(): void
Expand Down

0 comments on commit 9f136fb

Please sign in to comment.