@@ -243,6 +243,15 @@ public function handleUploadRequest($options = []): ResponseInterface
243243 ]);
244244 }
245245
246+ public function respondRangeNotSatisfiable (string $ responseID , int $ start , int $ end , int $ size ): Response
247+ {
248+ $ this ->responseBuilder = EmptyBuilder::class;
249+
250+ return $ this ->respondEmpty ($ responseID )
251+ ->withStatus (416 ) // Range Not Satisfiable
252+ ->withHeader ('Content-Range ' , "bytes $ start- $ end/ $ size " );
253+ }
254+
246255 /**
247256 * Set caching headers
248257 *
@@ -281,12 +290,9 @@ public function respondWithMedia(Media $Media, $variant, $responseID, $responseD
281290
282291 list (, $ range ) = explode ('= ' , $ _server ['HTTP_RANGE ' ], 2 );
283292
293+ // comma indicates multiple ranges which we currently do not support
284294 if (strpos ($ range , ', ' ) !== false ) {
285- $ this ->responseBuilder = EmptyBuilder::class;
286-
287- return $ this ->respondEmpty ($ responseID )
288- ->withStatus (416 ) // Range Not Satisfiable
289- ->withHeader ('Content-Range ' , "bytes $ start- $ end/ $ size " );
295+ return $ this ->respondRangeNotSatisfiable ($ responseID , $ start , $ end , $ size );
290296 }
291297
292298 if ($ range == '- ' ) { // missing range start and end
@@ -299,12 +305,10 @@ public function respondWithMedia(Media $Media, $variant, $responseID, $responseD
299305
300306
301307 $ chunkEnd = ($ chunkEnd > $ end ) ? $ end : $ chunkEnd ;
302- if ($ chunkStart > $ chunkEnd || $ chunkStart > $ size - 1 || $ chunkEnd >= $ size ) {
303- $ this ->responseBuilder = EmptyBuilder::class;
304308
305- return $ this -> respondEmpty ( $ responseID )
306- -> withStatus ( 416 ) // Range Not Satisfiable
307- -> withHeader ( ' Content-Range ' , " bytes $ start- $ end/ $ size" );
309+ // requested content out of bounds
310+ if ( $ chunkStart > $ chunkEnd || $ chunkStart > $ size - 1 || $ chunkEnd >= $ size ) {
311+ return $ this -> respondRangeNotSatisfiable ( $ responseID , $ start, $ end, $ size );
308312 }
309313
310314 $ start = intval ($ chunkStart );
0 commit comments