Skip to content

Commit 7ef23ff

Browse files
committed
Fixed error for HTTP/2.0 protocol signature
Protocol name according to RFC standards should be HTTP/2, but webservers also use HTTP/2.0
1 parent a049305 commit 7ef23ff

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

src/MessageMethodsTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ trait MessageMethodsTrait
2121
private string $version;
2222
private array $headers;
2323

24-
private array $supportedProtocolVersions = ['1.0', '1.1', '2'];
24+
private array $supportedProtocolVersions = ['1.0', '1.1', '2', '2.0'];
2525

2626
private array $headerNames = [];
2727

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

205205
return $illegalCharset || $invalidLineBreak;
206206
}

src/ServerData.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,7 @@ public function uploadedFiles(): array
9797

9898
private function protocolVersion(): string
9999
{
100-
return isset($this->server['SERVER_PROTOCOL'])
101-
? explode('/', $this->server['SERVER_PROTOCOL'])[1]
102-
: '1.1';
100+
return substr($this->server['SERVER_PROTOCOL'] ?? 'HTTP/1.1', 5) ?: '1.1';
103101
}
104102

105103
private function resolveUri(): UriInterface

tests/MessageMethodsTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ public function testInstantiatingMessage()
2828
public function testSetSupportedProtocolVersion()
2929
{
3030
$this->assertSame('2', $this->message([], '2')->getProtocolVersion());
31+
$this->assertSame('2.0', $this->message([], '2.0')->getProtocolVersion());
3132
$this->assertSame('1.0', $this->message()->withProtocolVersion('1.0')->getProtocolVersion());
3233
$this->assertSame('1.1', $this->message()->withProtocolVersion('1.1')->getProtocolVersion());
3334
$this->assertSame('2', $this->message()->withProtocolVersion('2')->getProtocolVersion());
35+
$this->assertSame('2.0', $this->message()->withProtocolVersion('2.0')->getProtocolVersion());
3436
}
3537

3638
public function testProtocolVersionChange_ReturnsNewObject()

0 commit comments

Comments
 (0)