Merge pull request #21054 from nextcloud/feature/noid/default-gzip-encoding-for-http-clients
Allow gzip encoded requests by default
This commit is contained in:
commit
0a45f44beb
|
@ -98,11 +98,12 @@ abstract class Fetcher {
|
||||||
|
|
||||||
$options = [
|
$options = [
|
||||||
'timeout' => 10,
|
'timeout' => 10,
|
||||||
'headers' => ['Accept-Encoding' => 'gzip'],
|
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($ETag !== '') {
|
if ($ETag !== '') {
|
||||||
$options['headers']['If-None-Match'] = $ETag;
|
$options['headers'] = [
|
||||||
|
'If-None-Match' => $ETag,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
$client = $this->clientService->newClient();
|
$client = $this->clientService->newClient();
|
||||||
|
|
|
@ -89,6 +89,10 @@ class Client implements IClient {
|
||||||
$options[RequestOptions::HEADERS]['User-Agent'] = 'Nextcloud Server Crawler';
|
$options[RequestOptions::HEADERS]['User-Agent'] = 'Nextcloud Server Crawler';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isset($options[RequestOptions::HEADERS]['Accept-Encoding'])) {
|
||||||
|
$options[RequestOptions::HEADERS]['Accept-Encoding'] = 'gzip';
|
||||||
|
}
|
||||||
|
|
||||||
return $options;
|
return $options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -249,15 +249,7 @@ abstract class FetcherBase extends TestCase {
|
||||||
$client
|
$client
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('get')
|
->method('get')
|
||||||
->with(
|
->with($this->endpoint)
|
||||||
$this->equalTo($this->endpoint),
|
|
||||||
$this->equalTo([
|
|
||||||
'timeout' => 10,
|
|
||||||
'headers' => [
|
|
||||||
'Accept-Encoding' => 'gzip',
|
|
||||||
]
|
|
||||||
])
|
|
||||||
)
|
|
||||||
->willReturn($response);
|
->willReturn($response);
|
||||||
$response
|
$response
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
|
@ -350,15 +342,7 @@ abstract class FetcherBase extends TestCase {
|
||||||
$client
|
$client
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('get')
|
->method('get')
|
||||||
->with(
|
->with($this->endpoint)
|
||||||
$this->equalTo($this->endpoint),
|
|
||||||
$this->equalTo([
|
|
||||||
'timeout' => 10,
|
|
||||||
'headers' => [
|
|
||||||
'Accept-Encoding' => 'gzip',
|
|
||||||
]
|
|
||||||
])
|
|
||||||
)
|
|
||||||
->willReturn($response);
|
->willReturn($response);
|
||||||
$response
|
$response
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
|
@ -446,15 +430,7 @@ abstract class FetcherBase extends TestCase {
|
||||||
$client
|
$client
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('get')
|
->method('get')
|
||||||
->with(
|
->with($this->endpoint)
|
||||||
$this->equalTo($this->endpoint),
|
|
||||||
$this->equalTo([
|
|
||||||
'timeout' => 10,
|
|
||||||
'headers' => [
|
|
||||||
'Accept-Encoding' => 'gzip',
|
|
||||||
]
|
|
||||||
])
|
|
||||||
)
|
|
||||||
->willReturn($response);
|
->willReturn($response);
|
||||||
$response
|
$response
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
|
@ -519,15 +495,7 @@ abstract class FetcherBase extends TestCase {
|
||||||
$client
|
$client
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('get')
|
->method('get')
|
||||||
->with(
|
->with($this->endpoint)
|
||||||
$this->equalTo($this->endpoint),
|
|
||||||
$this->equalTo([
|
|
||||||
'timeout' => 10,
|
|
||||||
'headers' => [
|
|
||||||
'Accept-Encoding' => 'gzip',
|
|
||||||
]
|
|
||||||
])
|
|
||||||
)
|
|
||||||
->willThrowException(new \Exception());
|
->willThrowException(new \Exception());
|
||||||
|
|
||||||
$this->assertSame([], $this->fetcher->get());
|
$this->assertSame([], $this->fetcher->get());
|
||||||
|
@ -584,8 +552,7 @@ abstract class FetcherBase extends TestCase {
|
||||||
$this->equalTo([
|
$this->equalTo([
|
||||||
'timeout' => 10,
|
'timeout' => 10,
|
||||||
'headers' => [
|
'headers' => [
|
||||||
'Accept-Encoding' => 'gzip',
|
'If-None-Match' => '"myETag"'
|
||||||
'If-None-Match' => '"myETag"',
|
|
||||||
]
|
]
|
||||||
])
|
])
|
||||||
)->willReturn($response);
|
)->willReturn($response);
|
||||||
|
@ -657,7 +624,6 @@ abstract class FetcherBase extends TestCase {
|
||||||
$this->equalTo([
|
$this->equalTo([
|
||||||
'timeout' => 10,
|
'timeout' => 10,
|
||||||
'headers' => [
|
'headers' => [
|
||||||
'Accept-Encoding' => 'gzip',
|
|
||||||
'If-None-Match' => '"myETag"',
|
'If-None-Match' => '"myETag"',
|
||||||
]
|
]
|
||||||
])
|
])
|
||||||
|
@ -744,9 +710,6 @@ abstract class FetcherBase extends TestCase {
|
||||||
$this->equalTo($this->endpoint),
|
$this->equalTo($this->endpoint),
|
||||||
$this->equalTo([
|
$this->equalTo([
|
||||||
'timeout' => 10,
|
'timeout' => 10,
|
||||||
'headers' => [
|
|
||||||
'Accept-Encoding' => 'gzip',
|
|
||||||
],
|
|
||||||
])
|
])
|
||||||
)
|
)
|
||||||
->willReturn($response);
|
->willReturn($response);
|
||||||
|
|
|
@ -292,6 +292,7 @@ class ClientTest extends \Test\TestCase {
|
||||||
],
|
],
|
||||||
'headers' => [
|
'headers' => [
|
||||||
'User-Agent' => 'Nextcloud Server Crawler',
|
'User-Agent' => 'Nextcloud Server Crawler',
|
||||||
|
'Accept-Encoding' => 'gzip',
|
||||||
],
|
],
|
||||||
'timeout' => 30,
|
'timeout' => 30,
|
||||||
];
|
];
|
||||||
|
@ -467,7 +468,8 @@ class ClientTest extends \Test\TestCase {
|
||||||
$this->assertEquals([
|
$this->assertEquals([
|
||||||
'verify' => \OC::$SERVERROOT . '/resources/config/ca-bundle.crt',
|
'verify' => \OC::$SERVERROOT . '/resources/config/ca-bundle.crt',
|
||||||
'headers' => [
|
'headers' => [
|
||||||
'User-Agent' => 'Nextcloud Server Crawler'
|
'User-Agent' => 'Nextcloud Server Crawler',
|
||||||
|
'Accept-Encoding' => 'gzip',
|
||||||
],
|
],
|
||||||
'timeout' => 30,
|
'timeout' => 30,
|
||||||
], self::invokePrivate($this->client, 'buildRequestOptions', [[]]));
|
], self::invokePrivate($this->client, 'buildRequestOptions', [[]]));
|
||||||
|
@ -502,7 +504,8 @@ class ClientTest extends \Test\TestCase {
|
||||||
'https' => 'foo'
|
'https' => 'foo'
|
||||||
],
|
],
|
||||||
'headers' => [
|
'headers' => [
|
||||||
'User-Agent' => 'Nextcloud Server Crawler'
|
'User-Agent' => 'Nextcloud Server Crawler',
|
||||||
|
'Accept-Encoding' => 'gzip',
|
||||||
],
|
],
|
||||||
'timeout' => 30,
|
'timeout' => 30,
|
||||||
], self::invokePrivate($this->client, 'buildRequestOptions', [[]]));
|
], self::invokePrivate($this->client, 'buildRequestOptions', [[]]));
|
||||||
|
@ -538,7 +541,8 @@ class ClientTest extends \Test\TestCase {
|
||||||
'no' => ['bar']
|
'no' => ['bar']
|
||||||
],
|
],
|
||||||
'headers' => [
|
'headers' => [
|
||||||
'User-Agent' => 'Nextcloud Server Crawler'
|
'User-Agent' => 'Nextcloud Server Crawler',
|
||||||
|
'Accept-Encoding' => 'gzip',
|
||||||
],
|
],
|
||||||
'timeout' => 30,
|
'timeout' => 30,
|
||||||
], self::invokePrivate($this->client, 'buildRequestOptions', [[]]));
|
], self::invokePrivate($this->client, 'buildRequestOptions', [[]]));
|
||||||
|
|
Loading…
Reference in New Issue