From 8adedd1885e9bc61fd35bdf7cecb0f966d2b4539 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Tue, 29 Nov 2022 13:00:54 -0800 Subject: [PATCH] video: abort curl on termination --- lib/Controller/VideoController.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/Controller/VideoController.php b/lib/Controller/VideoController.php index 5ee6f9b6..f7fc008f 100644 --- a/lib/Controller/VideoController.php +++ b/lib/Controller/VideoController.php @@ -237,6 +237,9 @@ class VideoController extends ApiBase curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($ch, CURLOPT_HEADER, 0); + // Catch connection abort here + ignore_user_abort(true); + // Stream the response to the browser without reading it into memory $headersWritten = false; curl_setopt($ch, CURLOPT_WRITEFUNCTION, function($curl, $data) use (&$headersWritten) { @@ -248,13 +251,17 @@ class VideoController extends ApiBase $headersWritten = true; $contentType = curl_getinfo($curl, CURLINFO_CONTENT_TYPE); header("Content-Type: {$contentType}"); - header("HTTP/1.1 {$returnCode}"); header('Cache-Control: no-cache, no-store, must-revalidate'); + http_response_code($returnCode); } print($data); ob_flush(); flush(); + + if (connection_aborted()) { + return -1; // stop the transfer + } } return strlen($data);