diff --git a/src/Http/Message.php b/src/Http/Message.php index 3506943..d48afd0 100644 --- a/src/Http/Message.php +++ b/src/Http/Message.php @@ -172,7 +172,8 @@ private function handleHeader(string $name, string|array $value): void } $value = is_array($value) ? $value : [$value]; foreach ($value as $content) { - if (!(is_string($content) || is_numeric($content)) || empty($content = trim($content))) { + $content = trim($content); + if ('' === $content) { throw new InvalidArgumentException("Invalid header value(s) provided."); } $this->headers[strtolower($name)][$name][] = $content; diff --git a/tests/suites/http/RequestTest.php b/tests/suites/http/RequestTest.php index 07631de..e89636e 100644 --- a/tests/suites/http/RequestTest.php +++ b/tests/suites/http/RequestTest.php @@ -232,4 +232,40 @@ public function testHaederValueError(): void $this->expectExceptionMessage("Invalid header value(s) provided."); $request->withHeader('name', ''); } + + /** + * @dataProvider provideInvalidHeaderValues + * @ + */ + public function testHeaderValueInvalidVariants($value): void + { + $request = new Request(); + $this->expectException(InvalidArgumentException::class); + $request->withHeader('name', $value); + } + + public static function provideInvalidHeaderValues(): \Generator + { + yield ['']; + yield [' ']; + } + + /** + * @dataProvider provideValidHeaderValues + * @ + */ + public function testHeaderValueValidVariants($value): void + { + $request = new Request(); + $request = $request->withHeader('name', $value); + $this->assertInstanceOf(Request::class, $request); + } + + public static function provideValidHeaderValues(): \Generator + { + yield ['null']; + yield ['0']; + yield [' 0']; + yield ['1']; + } }