diff --git a/src/Http/Request.php b/src/Http/Request.php index 8332d99..c976212 100755 --- a/src/Http/Request.php +++ b/src/Http/Request.php @@ -332,7 +332,16 @@ abstract public function removeHeader(string $key): static; */ public function getSize(): int { - return \mb_strlen(\implode("\n", $this->generateHeaders()), '8bit') + \mb_strlen(\file_get_contents('php://input'), '8bit'); + $headers = $this->generateHeaders(); + $headerStrings = []; + foreach ($headers as $key => $value) { + if (\is_array($value)) { + $headerStrings[] = $key . ': ' . \implode(', ', $value); + } else { + $headerStrings[] = $key . ': ' . $value; + } + } + return \mb_strlen(\implode("\n", $headerStrings), '8bit') + \mb_strlen(\file_get_contents('php://input'), '8bit'); } /** diff --git a/tests/RequestTest.php b/tests/RequestTest.php index 55d49ee..02d8930 100755 --- a/tests/RequestTest.php +++ b/tests/RequestTest.php @@ -313,4 +313,23 @@ public function testCanGetRange() $this->assertEquals(null, $this->request->getRangeStart()); $this->assertEquals(null, $this->request->getRangeEnd()); } + + public function testCanGetSizeWithArrayHeaders() + { + $this->request->addHeader('content-type', 'application/json'); + + $reflection = new \ReflectionClass($this->request); + $headersProperty = $reflection->getProperty('headers'); + $headersProperty->setAccessible(true); + + $headers = $headersProperty->getValue($this->request) ?? []; + $headers['accept'] = ['application/json', 'text/html']; + $headers['x-custom'] = ['value1', 'value2', 'value3']; + $headersProperty->setValue($this->request, $headers); + + $size = $this->request->getSize(); + + $this->assertIsInt($size); + $this->assertGreaterThan(0, $size); + } }