diff --git a/classes/Video.php b/classes/Video.php index a53b344..02f308c 100644 --- a/classes/Video.php +++ b/classes/Video.php @@ -562,11 +562,11 @@ class Video * * @return Response */ - public function getHttpResponse() + public function getHttpResponse(array $headers = []) { $client = new Client(); $urls = $this->getUrl(); - return $client->request('GET', $urls[0], ['stream' => true]); + return $client->request('GET', $urls[0], ['stream' => true, 'headers' => $headers]); } } diff --git a/controllers/FrontController.php b/controllers/FrontController.php index 8b1758e..1585f4f 100644 --- a/controllers/FrontController.php +++ b/controllers/FrontController.php @@ -15,7 +15,6 @@ use Alltube\Video; use Aura\Session\Segment; use Aura\Session\SessionFactory; use Exception; -use GuzzleHttp\Client; use Psr\Container\ContainerInterface; use Slim\Container; use Slim\Http\Request; @@ -394,15 +393,8 @@ class FrontController $response = $response->withHeader('Content-Type', 'video/'.$this->video->ext); $body = new Stream($this->video->getM3uStream()); } else { - $client = new Client(); - $stream = $client->request( - 'GET', - $this->video->getUrl(), - [ - 'stream' => true, - 'headers' => ['Range' => $request->getHeader('Range')], - ] - ); + $stream = $this->video->getHttpResponse(['Range' => $request->getHeader('Range')]); + $response = $response->withHeader('Content-Type', $stream->getHeader('Content-Type')); $response = $response->withHeader('Content-Length', $stream->getHeader('Content-Length')); $response = $response->withHeader('Accept-Ranges', $stream->getHeader('Accept-Ranges'));