From 4fa6e4b62f522d0cc38d33745ec42a5fcfc829ab Mon Sep 17 00:00:00 2001 From: Johan Janssens Date: Wed, 10 Nov 2021 21:48:28 +0100 Subject: [PATCH 1/2] #277 - Do not send Content-Length if streaming --- .../library/dispatcher/response/transport/http.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/code/libraries/joomlatools/library/dispatcher/response/transport/http.php b/code/libraries/joomlatools/library/dispatcher/response/transport/http.php index f997f1578..e0214c246 100644 --- a/code/libraries/joomlatools/library/dispatcher/response/transport/http.php +++ b/code/libraries/joomlatools/library/dispatcher/response/transport/http.php @@ -172,8 +172,8 @@ public function send(KDispatcherResponseInterface $response) $response->setContentType('application/octet-stream'); } - //Add Content-Length if not present - if(!$response->headers->has('Content-Length')) { + //Add Content-Length if not present and not streaming + if(!$response->headers->has('Content-Length') && !$request->isStreaming()) { $response->headers->set('Content-Length', $response->getStream()->getSize()); } } @@ -239,3 +239,4 @@ public function send(KDispatcherResponseInterface $response) return parent::send($response); } } + From 7469525cf871747a7728e5b382f57659937e227d Mon Sep 17 00:00:00 2001 From: Johan Janssens Date: Wed, 10 Nov 2021 21:49:36 +0100 Subject: [PATCH 2/2] #277 - Safari sends an initial 0-1 range request to check if range requests are working. If the response contains Content-Length this request fails. --- .../library/dispatcher/response/transport/stream.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/code/libraries/joomlatools/library/dispatcher/response/transport/stream.php b/code/libraries/joomlatools/library/dispatcher/response/transport/stream.php index 261032b95..beeecbdb8 100644 --- a/code/libraries/joomlatools/library/dispatcher/response/transport/stream.php +++ b/code/libraries/joomlatools/library/dispatcher/response/transport/stream.php @@ -224,8 +224,12 @@ public function send(KDispatcherResponseInterface $response) $size = $this->getFileSize($response); $response->setStatus(KHttpResponse::PARTIAL_CONTENT); - $response->headers->set('Content-Length', $range - $offset + 1); $response->headers->set('Content-Range', sprintf('bytes %s-%s/%s', $offset, $range, $size)); + + //Safari sends an initial 0-1 range request, which fails if a Content-Length is provided in response on HTTP2 + if(($range - $offset) > 1) { + $response->headers->set('Content-Length', $range - $offset); + } } if($response->isError())