From 103efb11e9dca5853b86fbbdb8a89d7ea0d562bc Mon Sep 17 00:00:00 2001 From: Unpublished Date: Mon, 22 Feb 2021 15:59:26 +0100 Subject: [PATCH] Add X-Accel-Buffering header to downloads Signed-off-by: Unpublished --- apps/dav/lib/Connector/Sabre/FilesPlugin.php | 1 + apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php | 7 +++++-- lib/private/Streamer.php | 1 + lib/private/legacy/OC_Files.php | 1 + 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/apps/dav/lib/Connector/Sabre/FilesPlugin.php b/apps/dav/lib/Connector/Sabre/FilesPlugin.php index fa948f3862..a2090eb540 100644 --- a/apps/dav/lib/Connector/Sabre/FilesPlugin.php +++ b/apps/dav/lib/Connector/Sabre/FilesPlugin.php @@ -281,6 +281,7 @@ class FilesPlugin extends ServerPlugin { $response->addHeader('OC-Checksum', $checksum); } } + $response->addHeader('X-Accel-Buffering', 'no'); } /** diff --git a/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php index ea9bc371d5..19f38cda9d 100644 --- a/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php @@ -576,9 +576,12 @@ class FilesPluginTest extends TestCase { ->willReturn($isClumsyAgent); $response - ->expects($this->once()) + ->expects($this->exactly(2)) ->method('addHeader') - ->with('Content-Disposition', $contentDispositionHeader); + ->withConsecutive( + ['Content-Disposition', $contentDispositionHeader], + ['X-Accel-Buffering', 'no'] + ); $this->plugin->httpGet($request, $response); } diff --git a/lib/private/Streamer.php b/lib/private/Streamer.php index 0e3018f77b..6b5507cb9a 100644 --- a/lib/private/Streamer.php +++ b/lib/private/Streamer.php @@ -95,6 +95,7 @@ class Streamer { * @param string $name */ public function sendHeaders($name) { + header('X-Accel-Buffering: no'); $extension = $this->streamerInstance instanceof ZipStreamer ? '.zip' : '.tar'; $fullName = $name . $extension; $this->streamerInstance->sendHeaders($fullName); diff --git a/lib/private/legacy/OC_Files.php b/lib/private/legacy/OC_Files.php index addee2358d..52dd759373 100644 --- a/lib/private/legacy/OC_Files.php +++ b/lib/private/legacy/OC_Files.php @@ -98,6 +98,7 @@ class OC_Files { } } header('Content-Type: '.$type, true); + header('X-Accel-Buffering: no'); } /**