aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2020-05-20 15:49:20 +0200
committerGitHub <noreply@github.com>2020-05-20 15:49:20 +0200
commit0a45f44bebb10d01d4f8140830b6b186199d56ba (patch)
treec3cb08c2c3b29bd257af991a0736326e64df8b0c
parent526905cfc28f701c828c439fba40d9745d3a3ba3 (diff)
parent8123737a406a969b6cb8cce5f58355b7b8a9e053 (diff)
downloadnextcloud-server-0a45f44bebb10d01d4f8140830b6b186199d56ba.tar.gz
nextcloud-server-0a45f44bebb10d01d4f8140830b6b186199d56ba.zip
Merge pull request #21054 from nextcloud/feature/noid/default-gzip-encoding-for-http-clients
Allow gzip encoded requests by default
-rw-r--r--lib/private/App/AppStore/Fetcher/Fetcher.php5
-rw-r--r--lib/private/Http/Client/Client.php4
-rw-r--r--tests/lib/App/AppStore/Fetcher/FetcherBase.php47
-rw-r--r--tests/lib/Http/Client/ClientTest.php10
4 files changed, 19 insertions, 47 deletions
diff --git a/lib/private/App/AppStore/Fetcher/Fetcher.php b/lib/private/App/AppStore/Fetcher/Fetcher.php
index c109bacf135..bb39637891f 100644
--- a/lib/private/App/AppStore/Fetcher/Fetcher.php
+++ b/lib/private/App/AppStore/Fetcher/Fetcher.php
@@ -98,11 +98,12 @@ abstract class Fetcher {
$options = [
'timeout' => 10,
- 'headers' => ['Accept-Encoding' => 'gzip'],
];
if ($ETag !== '') {
- $options['headers']['If-None-Match'] = $ETag;
+ $options['headers'] = [
+ 'If-None-Match' => $ETag,
+ ];
}
$client = $this->clientService->newClient();
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/App/AppStore/Fetcher/FetcherBase.php b/tests/lib/App/AppStore/Fetcher/FetcherBase.php
index 45f3f22b9d4..2e04f22760e 100644
--- a/tests/lib/App/AppStore/Fetcher/FetcherBase.php
+++ b/tests/lib/App/AppStore/Fetcher/FetcherBase.php
@@ -249,15 +249,7 @@ abstract class FetcherBase extends TestCase {
$client
->expects($this->once())
->method('get')
- ->with(
- $this->equalTo($this->endpoint),
- $this->equalTo([
- 'timeout' => 10,
- 'headers' => [
- 'Accept-Encoding' => 'gzip',
- ]
- ])
- )
+ ->with($this->endpoint)
->willReturn($response);
$response
->expects($this->once())
@@ -350,15 +342,7 @@ abstract class FetcherBase extends TestCase {
$client
->expects($this->once())
->method('get')
- ->with(
- $this->equalTo($this->endpoint),
- $this->equalTo([
- 'timeout' => 10,
- 'headers' => [
- 'Accept-Encoding' => 'gzip',
- ]
- ])
- )
+ ->with($this->endpoint)
->willReturn($response);
$response
->expects($this->once())
@@ -446,15 +430,7 @@ abstract class FetcherBase extends TestCase {
$client
->expects($this->once())
->method('get')
- ->with(
- $this->equalTo($this->endpoint),
- $this->equalTo([
- 'timeout' => 10,
- 'headers' => [
- 'Accept-Encoding' => 'gzip',
- ]
- ])
- )
+ ->with($this->endpoint)
->willReturn($response);
$response
->expects($this->once())
@@ -519,15 +495,7 @@ abstract class FetcherBase extends TestCase {
$client
->expects($this->once())
->method('get')
- ->with(
- $this->equalTo($this->endpoint),
- $this->equalTo([
- 'timeout' => 10,
- 'headers' => [
- 'Accept-Encoding' => 'gzip',
- ]
- ])
- )
+ ->with($this->endpoint)
->willThrowException(new \Exception());
$this->assertSame([], $this->fetcher->get());
@@ -584,8 +552,7 @@ abstract class FetcherBase extends TestCase {
$this->equalTo([
'timeout' => 10,
'headers' => [
- 'Accept-Encoding' => 'gzip',
- 'If-None-Match' => '"myETag"',
+ 'If-None-Match' => '"myETag"'
]
])
)->willReturn($response);
@@ -657,7 +624,6 @@ abstract class FetcherBase extends TestCase {
$this->equalTo([
'timeout' => 10,
'headers' => [
- 'Accept-Encoding' => 'gzip',
'If-None-Match' => '"myETag"',
]
])
@@ -744,9 +710,6 @@ abstract class FetcherBase extends TestCase {
$this->equalTo($this->endpoint),
$this->equalTo([
'timeout' => 10,
- 'headers' => [
- 'Accept-Encoding' => 'gzip',
- ],
])
)
->willReturn($response);
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', [[]]));