From 8bcd1c31da7a02e78435aa49508ed3787b11867d Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Wed, 20 May 2020 11:08:27 +0200 Subject: [PATCH] Allow gzip encoded requests by default Signed-off-by: Morris Jobke --- lib/private/Http/Client/Client.php | 4 ++++ tests/lib/Http/Client/ClientTest.php | 10 +++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/private/Http/Client/Client.php b/lib/private/Http/Client/Client.php index d19f1124a23..af43df6365f 100644 --- a/lib/private/Http/Client/Client.php +++ b/lib/private/Http/Client/Client.php @@ -89,6 +89,10 @@ class Client implements IClient { $options[RequestOptions::HEADERS]['User-Agent'] = 'Nextcloud Server Crawler'; } + if (!isset($options[RequestOptions::HEADERS]['Accept-Encoding'])) { + $options[RequestOptions::HEADERS]['Accept-Encoding'] = 'gzip'; + } + return $options; } diff --git a/tests/lib/Http/Client/ClientTest.php b/tests/lib/Http/Client/ClientTest.php index b136a0ca300..a0c4d75c1bd 100644 --- a/tests/lib/Http/Client/ClientTest.php +++ b/tests/lib/Http/Client/ClientTest.php @@ -292,6 +292,7 @@ class ClientTest extends \Test\TestCase { ], 'headers' => [ 'User-Agent' => 'Nextcloud Server Crawler', + 'Accept-Encoding' => 'gzip', ], 'timeout' => 30, ]; @@ -467,7 +468,8 @@ class ClientTest extends \Test\TestCase { $this->assertEquals([ 'verify' => \OC::$SERVERROOT . '/resources/config/ca-bundle.crt', 'headers' => [ - 'User-Agent' => 'Nextcloud Server Crawler' + 'User-Agent' => 'Nextcloud Server Crawler', + 'Accept-Encoding' => 'gzip', ], 'timeout' => 30, ], self::invokePrivate($this->client, 'buildRequestOptions', [[]])); @@ -502,7 +504,8 @@ class ClientTest extends \Test\TestCase { 'https' => 'foo' ], 'headers' => [ - 'User-Agent' => 'Nextcloud Server Crawler' + 'User-Agent' => 'Nextcloud Server Crawler', + 'Accept-Encoding' => 'gzip', ], 'timeout' => 30, ], self::invokePrivate($this->client, 'buildRequestOptions', [[]])); @@ -538,7 +541,8 @@ class ClientTest extends \Test\TestCase { 'no' => ['bar'] ], 'headers' => [ - 'User-Agent' => 'Nextcloud Server Crawler' + 'User-Agent' => 'Nextcloud Server Crawler', + 'Accept-Encoding' => 'gzip', ], 'timeout' => 30, ], self::invokePrivate($this->client, 'buildRequestOptions', [[]]));