Skip to content

Commit ee2eb1c

Browse files
committed
Merge branch '4.4' into 5.4
* 4.4: Update ExceptionInterface.php Flush with flush() after ob_end_flush() [HttpFoundation] Fix deleteFileAfterSend on client abortion fix sending request to paths containing multiple slashes
2 parents 8dd6bb7 + ec69d4e commit ee2eb1c

File tree

5 files changed

+61
-3
lines changed

5 files changed

+61
-3
lines changed

src/Symfony/Component/BrowserKit/AbstractBrowser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ protected function getAbsoluteUri(string $uri)
658658
}
659659

660660
// protocol relative URL
661-
if (0 === strpos($uri, '//')) {
661+
if ('' !== trim($uri, '/') && str_starts_with($uri, '//')) {
662662
return parse_url($currentUri, \PHP_URL_SCHEME).':'.$uri;
663663
}
664664

src/Symfony/Component/BrowserKit/Tests/HttpBrowserTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,30 @@ public function testMultiPartRequestWithAdditionalParametersOfTheSameName()
180180
]);
181181
}
182182

183+
/**
184+
* @dataProvider forwardSlashesRequestPathProvider
185+
*/
186+
public function testMultipleForwardSlashesRequestPath(string $requestPath)
187+
{
188+
$client = $this->createMock(HttpClientInterface::class);
189+
$client
190+
->expects($this->once())
191+
->method('request')
192+
->with('GET', 'http://localhost'.$requestPath)
193+
->willReturn($this->createMock(ResponseInterface::class));
194+
$browser = new HttpBrowser($client);
195+
$browser->request('GET', $requestPath);
196+
}
197+
198+
public function forwardSlashesRequestPathProvider()
199+
{
200+
return [
201+
'one slash' => ['/'],
202+
'two slashes' => ['//'],
203+
'multiple slashes' => ['////'],
204+
];
205+
}
206+
183207
private function uploadFile(string $data): string
184208
{
185209
$path = tempnam(sys_get_temp_dir(), 'http');

src/Symfony/Component/HttpFoundation/BinaryFileResponse.php

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class BinaryFileResponse extends Response
3434
protected $offset = 0;
3535
protected $maxlen = -1;
3636
protected $deleteFileAfterSend = false;
37+
protected $chunkSize = 8 * 1024;
3738

3839
/**
3940
* @param \SplFileInfo|string $file The file to stream
@@ -125,6 +126,22 @@ public function getFile()
125126
return $this->file;
126127
}
127128

129+
/**
130+
* Sets the response stream chunk size.
131+
*
132+
* @return $this
133+
*/
134+
public function setChunkSize(int $chunkSize): self
135+
{
136+
if ($chunkSize < 1 || $chunkSize > \PHP_INT_MAX) {
137+
throw new \LogicException('The chunk size of a BinaryFileResponse cannot be less than 1 or greater than PHP_INT_MAX.');
138+
}
139+
140+
$this->chunkSize = $chunkSize;
141+
142+
return $this;
143+
}
144+
128145
/**
129146
* Automatically sets the Last-Modified header according the file modification date.
130147
*
@@ -306,7 +323,23 @@ public function sendContent()
306323
$out = fopen('php://output', 'w');
307324
$file = fopen($this->file->getPathname(), 'r');
308325

309-
stream_copy_to_stream($file, $out, $this->maxlen, $this->offset);
326+
ignore_user_abort(true);
327+
328+
if (0 !== $this->offset) {
329+
fseek($file, $this->offset);
330+
}
331+
332+
$length = $this->maxlen;
333+
while ($length && !feof($file)) {
334+
$read = ($length > $this->chunkSize) ? $this->chunkSize : $length;
335+
$length -= $read;
336+
337+
stream_copy_to_stream($file, $out, $read);
338+
339+
if (connection_aborted()) {
340+
break;
341+
}
342+
}
310343

311344
fclose($out);
312345
fclose($file);

src/Symfony/Component/HttpFoundation/Response.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,6 +1245,7 @@ public static function closeOutputBuffers(int $targetLevel, bool $flush): void
12451245
while ($level-- > $targetLevel && ($s = $status[$level]) && (!isset($s['del']) ? !isset($s['flags']) || ($s['flags'] & $flags) === $flags : $s['del'])) {
12461246
if ($flush) {
12471247
ob_end_flush();
1248+
flush();
12481249
} else {
12491250
ob_end_clean();
12501251
}

src/Symfony/Component/Messenger/Exception/ExceptionInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Symfony\Component\Messenger\Exception;
1313

1414
/**
15-
* Base Message component's exception.
15+
* Base Messenger component's exception.
1616
*
1717
* @author Samuel Roze <[email protected]>
1818
*/

0 commit comments

Comments
 (0)