From 745667e426e595437cfe698c792863ec61d2e77c Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Tue, 19 May 2020 23:04:51 +0200 Subject: [PATCH] Compress the appstore requests by default In test it reduced the transfered data from 5 MB to 2 MB. This should reduce the load on the appstore significantly. Signed-off-by: Morris Jobke --- lib/private/App/AppStore/Fetcher/Fetcher.php | 5 +- .../lib/App/AppStore/Fetcher/FetcherBase.php | 47 +++++++++++++++++-- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/lib/private/App/AppStore/Fetcher/Fetcher.php b/lib/private/App/AppStore/Fetcher/Fetcher.php index bb39637891..c109bacf13 100644 --- a/lib/private/App/AppStore/Fetcher/Fetcher.php +++ b/lib/private/App/AppStore/Fetcher/Fetcher.php @@ -98,12 +98,11 @@ 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/tests/lib/App/AppStore/Fetcher/FetcherBase.php b/tests/lib/App/AppStore/Fetcher/FetcherBase.php index 2e04f22760..45f3f22b9d 100644 --- a/tests/lib/App/AppStore/Fetcher/FetcherBase.php +++ b/tests/lib/App/AppStore/Fetcher/FetcherBase.php @@ -249,7 +249,15 @@ abstract class FetcherBase extends TestCase { $client ->expects($this->once()) ->method('get') - ->with($this->endpoint) + ->with( + $this->equalTo($this->endpoint), + $this->equalTo([ + 'timeout' => 10, + 'headers' => [ + 'Accept-Encoding' => 'gzip', + ] + ]) + ) ->willReturn($response); $response ->expects($this->once()) @@ -342,7 +350,15 @@ abstract class FetcherBase extends TestCase { $client ->expects($this->once()) ->method('get') - ->with($this->endpoint) + ->with( + $this->equalTo($this->endpoint), + $this->equalTo([ + 'timeout' => 10, + 'headers' => [ + 'Accept-Encoding' => 'gzip', + ] + ]) + ) ->willReturn($response); $response ->expects($this->once()) @@ -430,7 +446,15 @@ abstract class FetcherBase extends TestCase { $client ->expects($this->once()) ->method('get') - ->with($this->endpoint) + ->with( + $this->equalTo($this->endpoint), + $this->equalTo([ + 'timeout' => 10, + 'headers' => [ + 'Accept-Encoding' => 'gzip', + ] + ]) + ) ->willReturn($response); $response ->expects($this->once()) @@ -495,7 +519,15 @@ abstract class FetcherBase extends TestCase { $client ->expects($this->once()) ->method('get') - ->with($this->endpoint) + ->with( + $this->equalTo($this->endpoint), + $this->equalTo([ + 'timeout' => 10, + 'headers' => [ + 'Accept-Encoding' => 'gzip', + ] + ]) + ) ->willThrowException(new \Exception()); $this->assertSame([], $this->fetcher->get()); @@ -552,7 +584,8 @@ abstract class FetcherBase extends TestCase { $this->equalTo([ 'timeout' => 10, 'headers' => [ - 'If-None-Match' => '"myETag"' + 'Accept-Encoding' => 'gzip', + 'If-None-Match' => '"myETag"', ] ]) )->willReturn($response); @@ -624,6 +657,7 @@ abstract class FetcherBase extends TestCase { $this->equalTo([ 'timeout' => 10, 'headers' => [ + 'Accept-Encoding' => 'gzip', 'If-None-Match' => '"myETag"', ] ]) @@ -710,6 +744,9 @@ abstract class FetcherBase extends TestCase { $this->equalTo($this->endpoint), $this->equalTo([ 'timeout' => 10, + 'headers' => [ + 'Accept-Encoding' => 'gzip', + ], ]) ) ->willReturn($response);