Skip to content

Commit da74b77

Browse files
committed
range: change http error for too big content range value
1 parent 14691ab commit da74b77

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/Range/ContentRange.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace CodingSocks\UploadHandler\Range;
44

5+
use CodingSocks\UploadHandler\Exception\RequestEntityTooLargeHttpException;
56
use Illuminate\Http\Request;
67
use Illuminate\Http\Response;
78
use InvalidArgumentException;
@@ -67,7 +68,7 @@ protected function numericValue($value): float
6768
$floatVal = floatval($value);
6869

6970
if ($floatVal === INF) {
70-
throw new HttpException(Response::HTTP_INTERNAL_SERVER_ERROR, 'The content range value is too large');
71+
throw new RequestEntityTooLargeHttpException('The content range value is too large');
7172
}
7273

7374
return $floatVal;

tests/Range/ContentRangeTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace CodingSocks\UploadHandler\Tests\Range;
44

5+
use CodingSocks\UploadHandler\Exception\RequestEntityTooLargeHttpException;
56
use CodingSocks\UploadHandler\Range\ContentRange;
67
use Illuminate\Http\Request;
78
use InvalidArgumentException;
@@ -36,6 +37,14 @@ public function testArgumentValidation($contentRange, $expectedExceptionMessage)
3637
new ContentRange($contentRange);
3738
}
3839

40+
public function testRequestEntityTooLargeHttpException()
41+
{
42+
$this->expectException(RequestEntityTooLargeHttpException::class);
43+
$this->expectExceptionMessage('The content range value is too large');
44+
45+
new ContentRange(sprintf('bytes 40-49/%s', str_repeat('9', 350)));
46+
}
47+
3948
public function testIsFirst()
4049
{
4150
$range = new ContentRange('bytes 0-9/200');

0 commit comments

Comments
 (0)