Merge branch '4.3' into 4.4
* 4.3: [Cache] ignore unserialization failures in AbstractTagAwareAdapter::doDelete() [HttpClient] send `Accept: */*` by default, fix removing it when needed
This commit is contained in:
commit
f93b3a3653
@ -232,10 +232,14 @@ abstract class AbstractTagAwareAdapter implements TagAwareAdapterInterface, TagA
|
||||
unset($this->deferred[$key]);
|
||||
}
|
||||
|
||||
foreach ($this->doFetch($ids) as $id => $value) {
|
||||
foreach ($value['tags'] ?? [] as $tag) {
|
||||
$tagData[$this->getId(self::TAGS_PREFIX.$tag)][] = $id;
|
||||
try {
|
||||
foreach ($this->doFetch($ids) as $id => $value) {
|
||||
foreach ($value['tags'] ?? [] as $tag) {
|
||||
$tagData[$this->getId(self::TAGS_PREFIX.$tag)][] = $id;
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// ignore unserialization failures
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -81,7 +81,7 @@ class RedisTagAwareAdapter extends AbstractTagAwareAdapter
|
||||
}
|
||||
|
||||
// While pipeline isn't supported on RedisCluster, other setups will at least benefit from doing this in one op
|
||||
$results = $this->pipeline(static function () use ($serialized, $lifetime, $addTagData, $delTagData) {
|
||||
$results = $this->pipeline(static function () use ($serialized, $lifetime, $addTagData, $delTagData, $failed) {
|
||||
// Store cache items, force a ttl if none is set, as there is no MSETEX we need to set each one
|
||||
foreach ($serialized as $id => $value) {
|
||||
yield 'setEx' => [
|
||||
@ -93,11 +93,15 @@ class RedisTagAwareAdapter extends AbstractTagAwareAdapter
|
||||
|
||||
// Add and Remove Tags
|
||||
foreach ($addTagData as $tagId => $ids) {
|
||||
yield 'sAdd' => array_merge([$tagId], $ids);
|
||||
if (!$failed || $ids = array_diff($ids, $failed)) {
|
||||
yield 'sAdd' => array_merge([$tagId], $ids);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($delTagData as $tagId => $ids) {
|
||||
yield 'sRem' => array_merge([$tagId], $ids);
|
||||
if (!$failed || $ids = array_diff($ids, $failed)) {
|
||||
yield 'sRem' => array_merge([$tagId], $ids);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -244,7 +244,7 @@ final class CurlHttpClient implements HttpClientInterface, LoggerAwareInterface
|
||||
|
||||
// Prevent curl from sending its default Accept and Expect headers
|
||||
foreach (['accept', 'expect'] as $header) {
|
||||
if (!isset($options['normalized_headers'][$header])) {
|
||||
if (!isset($options['normalized_headers'][$header][0])) {
|
||||
$curlopts[CURLOPT_HTTPHEADER][] = $header.':';
|
||||
}
|
||||
}
|
||||
@ -441,7 +441,7 @@ final class CurlHttpClient implements HttpClientInterface, LoggerAwareInterface
|
||||
return 0 !== stripos($h, 'Host:');
|
||||
});
|
||||
|
||||
if (isset($options['normalized_headers']['authorization']) || isset($options['normalized_headers']['cookie'])) {
|
||||
if (isset($options['normalized_headers']['authorization'][0]) || isset($options['normalized_headers']['cookie'][0])) {
|
||||
$redirectHeaders['no_auth'] = array_filter($options['headers'], static function ($h) {
|
||||
return 0 !== stripos($h, 'Authorization:') && 0 !== stripos($h, 'Cookie:');
|
||||
});
|
||||
|
@ -55,7 +55,7 @@ trait HttpClientTrait
|
||||
}
|
||||
|
||||
if (!isset($options['normalized_headers']['accept'])) {
|
||||
$options['normalized_headers']['accept'] = [$options['headers'][] = 'Accept: *'];
|
||||
$options['normalized_headers']['accept'] = [$options['headers'][] = 'Accept: */*'];
|
||||
}
|
||||
|
||||
if (isset($options['body'])) {
|
||||
|
@ -21,6 +21,33 @@ abstract class HttpClientTestCase extends BaseHttpClientTestCase
|
||||
$this->markTestSkipped('Implemented as of version 4.4');
|
||||
}
|
||||
|
||||
public function testAcceptHeader()
|
||||
{
|
||||
$client = $this->getHttpClient(__FUNCTION__);
|
||||
|
||||
$response = $client->request('GET', 'http://localhost:8057');
|
||||
$requestHeaders = $response->toArray();
|
||||
|
||||
$this->assertSame('*/*', $requestHeaders['HTTP_ACCEPT']);
|
||||
|
||||
$response = $client->request('GET', 'http://localhost:8057', [
|
||||
'headers' => [
|
||||
'Accept' => 'foo/bar',
|
||||
],
|
||||
]);
|
||||
$requestHeaders = $response->toArray();
|
||||
|
||||
$this->assertSame('foo/bar', $requestHeaders['HTTP_ACCEPT']);
|
||||
|
||||
$response = $client->request('GET', 'http://localhost:8057', [
|
||||
'headers' => [
|
||||
'Accept' => null,
|
||||
],
|
||||
]);
|
||||
$requestHeaders = $response->toArray();
|
||||
|
||||
$this->assertArrayNotHasKey('HTTP_ACCEPT', $requestHeaders);
|
||||
|
||||
public function testToStream()
|
||||
{
|
||||
$client = $this->getHttpClient(__FUNCTION__);
|
||||
|
@ -172,7 +172,7 @@ class HttpClientTraitTest extends TestCase
|
||||
public function testAuthBearerOption()
|
||||
{
|
||||
[, $options] = self::prepareRequest('POST', 'http://example.com', ['auth_bearer' => 'foobar'], HttpClientInterface::OPTIONS_DEFAULTS);
|
||||
$this->assertSame(['Accept: *', 'Authorization: Bearer foobar'], $options['headers']);
|
||||
$this->assertSame(['Accept: */*', 'Authorization: Bearer foobar'], $options['headers']);
|
||||
$this->assertSame(['Authorization: Bearer foobar'], $options['normalized_headers']['authorization']);
|
||||
}
|
||||
|
||||
|
@ -36,6 +36,7 @@ class MockHttpClientTest extends HttpClientTestCase
|
||||
"SERVER_NAME": "127.0.0.1",
|
||||
"REQUEST_URI": "/",
|
||||
"REQUEST_METHOD": "GET",
|
||||
"HTTP_ACCEPT": "*/*",
|
||||
"HTTP_FOO": "baR",
|
||||
"HTTP_HOST": "localhost:8057"
|
||||
}';
|
||||
@ -114,6 +115,12 @@ class MockHttpClientTest extends HttpClientTestCase
|
||||
$responses[] = $mock;
|
||||
break;
|
||||
|
||||
case 'testAcceptHeader':
|
||||
$responses[] = new MockResponse($body, ['response_headers' => $headers]);
|
||||
$responses[] = new MockResponse(str_replace('*/*', 'foo/bar', $body), ['response_headers' => $headers]);
|
||||
$responses[] = new MockResponse(str_replace('"HTTP_ACCEPT": "*/*",', '', $body), ['response_headers' => $headers]);
|
||||
break;
|
||||
|
||||
case 'testResolve':
|
||||
$responses[] = new MockResponse($body, ['response_headers' => $headers]);
|
||||
$responses[] = new MockResponse($body, ['response_headers' => $headers]);
|
||||
|
Reference in New Issue
Block a user