From f10098e9f11a121080169218c0c4627127b2f857 Mon Sep 17 00:00:00 2001 From: Robin Chalas Date: Sun, 9 Feb 2020 18:57:03 +0100 Subject: [PATCH 1/5] [Security] Fix exception name in doc comments --- .../Security/Core/Exception/AuthenticationExpiredException.php | 2 +- .../Security/Guard/Provider/GuardAuthenticationProvider.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Security/Core/Exception/AuthenticationExpiredException.php b/src/Symfony/Component/Security/Core/Exception/AuthenticationExpiredException.php index 7bc174f05c..b45c948acd 100644 --- a/src/Symfony/Component/Security/Core/Exception/AuthenticationExpiredException.php +++ b/src/Symfony/Component/Security/Core/Exception/AuthenticationExpiredException.php @@ -12,7 +12,7 @@ namespace Symfony\Component\Security\Core\Exception; /** - * AuthenticationServiceException is thrown when an authenticated token becomes un-authenticated between requests. + * AuthenticationExpiredException is thrown when an authenticated token becomes un-authenticated between requests. * * In practice, this is due to the User changing between requests (e.g. password changes), * causes the token to become un-authenticated. diff --git a/src/Symfony/Component/Security/Guard/Provider/GuardAuthenticationProvider.php b/src/Symfony/Component/Security/Guard/Provider/GuardAuthenticationProvider.php index a78a21d49d..26890db367 100644 --- a/src/Symfony/Component/Security/Guard/Provider/GuardAuthenticationProvider.php +++ b/src/Symfony/Component/Security/Guard/Provider/GuardAuthenticationProvider.php @@ -82,7 +82,7 @@ class GuardAuthenticationProvider implements AuthenticationProviderInterface return $token; } - // this AccountStatusException causes the user to be logged out + // this AccountExpiredException causes the user to be logged out throw new AuthenticationExpiredException(); } From 7088ef78f741af1de2209443386c71944c7cca3c Mon Sep 17 00:00:00 2001 From: Matthias Meyer Date: Tue, 11 Feb 2020 11:10:58 +0100 Subject: [PATCH 2/5] [HttpClient] fix HttpClientDataCollector when handling canceled responses --- .../HttpClient/DataCollector/HttpClientDataCollector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpClient/DataCollector/HttpClientDataCollector.php b/src/Symfony/Component/HttpClient/DataCollector/HttpClientDataCollector.php index 5c3fed50c0..9247b7479a 100644 --- a/src/Symfony/Component/HttpClient/DataCollector/HttpClientDataCollector.php +++ b/src/Symfony/Component/HttpClient/DataCollector/HttpClientDataCollector.php @@ -120,7 +120,7 @@ final class HttpClientDataCollector extends DataCollector implements LateDataCol unset($info['http_method']); } - if ($trace['url'] === $info['url']) { + if (($info['url'] ?? null) === $trace['url']) { unset($info['url']); } From 6d1657b720fd12363286cf4a857fd8052bc36486 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 11 Feb 2020 14:51:01 +0100 Subject: [PATCH 3/5] [HttpClient] fix getting response content after its destructor throwed an HttpExceptionInterface --- .../HttpClient/Response/CurlResponse.php | 23 +++++++++---------- .../HttpClient/Response/NativeResponse.php | 10 ++++++-- .../HttpClient/Response/ResponseTrait.php | 2 ++ .../HttpClient/Test/HttpClientTestCase.php | 14 +++++++++++ 4 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/Symfony/Component/HttpClient/Response/CurlResponse.php b/src/Symfony/Component/HttpClient/Response/CurlResponse.php index c497cfc4fd..6a1be2e08a 100644 --- a/src/Symfony/Component/HttpClient/Response/CurlResponse.php +++ b/src/Symfony/Component/HttpClient/Response/CurlResponse.php @@ -16,6 +16,7 @@ use Symfony\Component\HttpClient\Chunk\FirstChunk; use Symfony\Component\HttpClient\Chunk\InformationalChunk; use Symfony\Component\HttpClient\Exception\TransportException; use Symfony\Component\HttpClient\Internal\CurlClientState; +use Symfony\Contracts\HttpClient\Exception\HttpExceptionInterface; use Symfony\Contracts\HttpClient\ResponseInterface; /** @@ -113,7 +114,7 @@ final class CurlResponse implements ResponseInterface $this->initializer = static function (self $response) { $waitFor = curl_getinfo($ch = $response->handle, CURLINFO_PRIVATE); - return 'H' === $waitFor[0] || 'D' === $waitFor[0]; + return 'H' === $waitFor[0]; }; // Schedule the request in a non-blocking way @@ -174,17 +175,15 @@ final class CurlResponse implements ResponseInterface return; // Unused pushed response } - $waitFor = curl_getinfo($this->handle, CURLINFO_PRIVATE); - - if ('C' === $waitFor[0] || '_' === $waitFor[0]) { - $this->close(); - } elseif ('H' === $waitFor[0]) { - $waitFor[0] = 'D'; // D = destruct - curl_setopt($this->handle, CURLOPT_PRIVATE, $waitFor); + $e = null; + $this->doDestruct(); + } catch (HttpExceptionInterface $e) { + throw $e; + } finally { + if (null !== $e) { + throw $e; } - $this->doDestruct(); - } finally { $this->close(); if (!$this->multi->openHandles) { @@ -304,7 +303,7 @@ final class CurlResponse implements ResponseInterface { $waitFor = @curl_getinfo($ch, CURLINFO_PRIVATE) ?: '_0'; - if ('H' !== $waitFor[0] && 'D' !== $waitFor[0]) { + if ('H' !== $waitFor[0]) { return \strlen($data); // Ignore HTTP trailers } @@ -370,7 +369,7 @@ final class CurlResponse implements ResponseInterface // Headers and redirects completed, time to get the response's content $multi->handlesActivity[$id][] = new FirstChunk(); - if ('D' === $waitFor[0] || 'HEAD' === $info['http_method'] || \in_array($statusCode, [204, 304], true)) { + if ('HEAD' === $info['http_method'] || \in_array($statusCode, [204, 304], true)) { $waitFor = '_0'; // no content expected $multi->handlesActivity[$id][] = null; $multi->handlesActivity[$id][] = null; diff --git a/src/Symfony/Component/HttpClient/Response/NativeResponse.php b/src/Symfony/Component/HttpClient/Response/NativeResponse.php index 7abe18abab..f7f458a47c 100644 --- a/src/Symfony/Component/HttpClient/Response/NativeResponse.php +++ b/src/Symfony/Component/HttpClient/Response/NativeResponse.php @@ -15,6 +15,7 @@ use Psr\Log\LoggerInterface; use Symfony\Component\HttpClient\Chunk\FirstChunk; use Symfony\Component\HttpClient\Exception\TransportException; use Symfony\Component\HttpClient\Internal\NativeClientState; +use Symfony\Contracts\HttpClient\Exception\HttpExceptionInterface; use Symfony\Contracts\HttpClient\ResponseInterface; /** @@ -84,11 +85,16 @@ final class NativeResponse implements ResponseInterface public function __destruct() { - $this->shouldBuffer = null; - try { + $e = null; $this->doDestruct(); + } catch (HttpExceptionInterface $e) { + throw $e; } finally { + if (null !== $e) { + throw $e; + } + $this->close(); // Clear the DNS cache when all requests completed diff --git a/src/Symfony/Component/HttpClient/Response/ResponseTrait.php b/src/Symfony/Component/HttpClient/Response/ResponseTrait.php index 8793a45184..000da5344d 100644 --- a/src/Symfony/Component/HttpClient/Response/ResponseTrait.php +++ b/src/Symfony/Component/HttpClient/Response/ResponseTrait.php @@ -294,6 +294,8 @@ trait ResponseTrait */ private function doDestruct() { + $this->shouldBuffer = true; + if ($this->initializer && null === $this->info['error']) { self::initialize($this); $this->checkStatusCode(); diff --git a/src/Symfony/Contracts/HttpClient/Test/HttpClientTestCase.php b/src/Symfony/Contracts/HttpClient/Test/HttpClientTestCase.php index aad712e3e8..851997c087 100644 --- a/src/Symfony/Contracts/HttpClient/Test/HttpClientTestCase.php +++ b/src/Symfony/Contracts/HttpClient/Test/HttpClientTestCase.php @@ -782,6 +782,20 @@ abstract class HttpClientTestCase extends TestCase $this->assertLessThan(4, $duration); } + public function testGetContentAfterDestruct() + { + $client = $this->getHttpClient(__FUNCTION__); + + $start = microtime(true); + + try { + $client->request('GET', 'http://localhost:8057/404'); + $this->fail(ClientExceptionInterface::class.' expected'); + } catch (ClientExceptionInterface $e) { + $this->assertSame('GET', $e->getResponse()->toArray(false)['REQUEST_METHOD']); + } + } + public function testProxy() { $client = $this->getHttpClient(__FUNCTION__); From d41ea2a02e49f02fb9a1436f1108c2de416af70b Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 11 Feb 2020 15:05:45 +0100 Subject: [PATCH 4/5] [HttpClient] remove useless code in test --- src/Symfony/Contracts/HttpClient/Test/HttpClientTestCase.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Symfony/Contracts/HttpClient/Test/HttpClientTestCase.php b/src/Symfony/Contracts/HttpClient/Test/HttpClientTestCase.php index 851997c087..de13686819 100644 --- a/src/Symfony/Contracts/HttpClient/Test/HttpClientTestCase.php +++ b/src/Symfony/Contracts/HttpClient/Test/HttpClientTestCase.php @@ -786,8 +786,6 @@ abstract class HttpClientTestCase extends TestCase { $client = $this->getHttpClient(__FUNCTION__); - $start = microtime(true); - try { $client->request('GET', 'http://localhost:8057/404'); $this->fail(ClientExceptionInterface::class.' expected'); From 7e734a33892aeb7c5071a35f52590401a31fa045 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 11 Feb 2020 15:25:58 +0100 Subject: [PATCH 5/5] [HttpClient] fix "undefined variable" --- src/Symfony/Component/HttpClient/Response/CurlResponse.php | 2 +- src/Symfony/Component/HttpClient/Response/NativeResponse.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpClient/Response/CurlResponse.php b/src/Symfony/Component/HttpClient/Response/CurlResponse.php index 6a1be2e08a..0a6597fb08 100644 --- a/src/Symfony/Component/HttpClient/Response/CurlResponse.php +++ b/src/Symfony/Component/HttpClient/Response/CurlResponse.php @@ -180,7 +180,7 @@ final class CurlResponse implements ResponseInterface } catch (HttpExceptionInterface $e) { throw $e; } finally { - if (null !== $e) { + if ($e ?? false) { throw $e; } diff --git a/src/Symfony/Component/HttpClient/Response/NativeResponse.php b/src/Symfony/Component/HttpClient/Response/NativeResponse.php index f7f458a47c..6fccfbef5a 100644 --- a/src/Symfony/Component/HttpClient/Response/NativeResponse.php +++ b/src/Symfony/Component/HttpClient/Response/NativeResponse.php @@ -91,7 +91,7 @@ final class NativeResponse implements ResponseInterface } catch (HttpExceptionInterface $e) { throw $e; } finally { - if (null !== $e) { + if ($e ?? false) { throw $e; }