Skip to content

Commit

Permalink
Fixed error for HTTP/2.0 protocol signature
Browse files Browse the repository at this point in the history
Protocol name according to RFC standards should be HTTP/2,
but webservers also use HTTP/2.0
  • Loading branch information
shudd3r committed Dec 4, 2022
1 parent a049305 commit 7ef23ff
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/MessageMethodsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ trait MessageMethodsTrait
private string $version;
private array $headers;

private array $supportedProtocolVersions = ['1.0', '1.1', '2'];
private array $supportedProtocolVersions = ['1.0', '1.1', '2', '2.0'];

private array $headerNames = [];

Expand Down Expand Up @@ -200,7 +200,7 @@ private function legalHeaderStrings(array $headerValues): bool
private function illegalHeaderChars(string $header): bool
{
$illegalCharset = preg_match("/[^\t\r\n\x20-\x7E\x80-\xFE]/", $header);
$invalidLineBreak = preg_match("/(?:[^\r]\n|\r[^\n]|\n[^ \t])/", $header);
$invalidLineBreak = preg_match("/([^\r]\n|\r[^\n]|\n[^ \t])/", $header);

return $illegalCharset || $invalidLineBreak;
}
Expand Down
4 changes: 1 addition & 3 deletions src/ServerData.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ public function uploadedFiles(): array

private function protocolVersion(): string
{
return isset($this->server['SERVER_PROTOCOL'])
? explode('/', $this->server['SERVER_PROTOCOL'])[1]
: '1.1';
return substr($this->server['SERVER_PROTOCOL'] ?? 'HTTP/1.1', 5) ?: '1.1';
}

private function resolveUri(): UriInterface
Expand Down
2 changes: 2 additions & 0 deletions tests/MessageMethodsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ public function testInstantiatingMessage()
public function testSetSupportedProtocolVersion()
{
$this->assertSame('2', $this->message([], '2')->getProtocolVersion());
$this->assertSame('2.0', $this->message([], '2.0')->getProtocolVersion());
$this->assertSame('1.0', $this->message()->withProtocolVersion('1.0')->getProtocolVersion());
$this->assertSame('1.1', $this->message()->withProtocolVersion('1.1')->getProtocolVersion());
$this->assertSame('2', $this->message()->withProtocolVersion('2')->getProtocolVersion());
$this->assertSame('2.0', $this->message()->withProtocolVersion('2.0')->getProtocolVersion());
}

public function testProtocolVersionChange_ReturnsNewObject()
Expand Down

0 comments on commit 7ef23ff

Please sign in to comment.