Skip to content

Commit aa83894

Browse files
fix: IBX-10849 Passing string as a value of Content-Lenght header
1 parent d5827d0 commit aa83894

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

src/bundle/IO/BinaryStreamResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ private function processRangeRequest(Request $request): void
245245

246246
$this->setStatusCode(Response::HTTP_PARTIAL_CONTENT);
247247
$this->headers->set('Content-Range', sprintf('bytes %s-%s/%s', $start, $end, $fileSize));
248-
$this->headers->set('Content-Length', $end - $start + 1);
248+
$this->headers->set('Content-Length', (string) ($end - $start + 1));
249249
}
250250
}
251251
}

tests/bundle/IO/BinaryStreamResponseTest.php

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ final class BinaryStreamResponseTest extends TestCase
2626
public function testSendContent(): void
2727
{
2828
$ioServiceMock = $this->createMock(IOServiceInterface::class);
29-
$binaryStreamResponse = $this->prepareBinaryStreamResponse($ioServiceMock);
29+
$request = $this->prepareRequest();
30+
$binaryStreamResponse = $this->prepareBinaryStreamResponse($ioServiceMock, $request);
3031

3132
file_put_contents('php://input', 'test data');
3233
$in = fopen('php://input', 'rb');
@@ -40,10 +41,42 @@ public function testSendContent(): void
4041
$binaryStreamResponse->sendContent();
4142
}
4243

43-
private function prepareBinaryStreamResponse(IOServiceInterface & MockObject $ioServiceMock): BinaryStreamResponse
44+
/**
45+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
46+
*/
47+
public function testSendRangeContent(): void
48+
{
49+
$ioServiceMock = $this->createMock(IOServiceInterface::class);
50+
$request = $this->prepareRequest(['Range' => 'bytes=0-499']);
51+
$binaryStreamResponse = $this->prepareBinaryStreamResponse($ioServiceMock, $request);
52+
53+
file_put_contents('php://input', 'test data');
54+
$in = fopen('php://input', 'rb');
55+
56+
$ioServiceMock
57+
->expects(self::once())
58+
->method('getFileInputStream')
59+
->with($binaryStreamResponse->getFile())
60+
->willReturn($in);
61+
62+
$binaryStreamResponse->sendContent();
63+
}
64+
65+
/**
66+
* @param array<string,string> $headers
67+
*/
68+
private function prepareRequest(array $headers = []): Request
4469
{
4570
$request = new Request();
71+
foreach ($headers as $name => $value) {
72+
$request->headers->set($name, $value);
73+
}
4674

75+
return $request;
76+
}
77+
78+
private function prepareBinaryStreamResponse(IOServiceInterface & MockObject $ioServiceMock, Request $request): BinaryStreamResponse
79+
{
4780
$binaryFile = new BinaryFile(['id' => 'foo.jpg', 'size' => 5321]);
4881
$binaryStreamResponse = new BinaryStreamResponse($binaryFile, $ioServiceMock);
4982

0 commit comments

Comments
 (0)