8000 Merge branch '5.0' · symfony/symfony@b84faa4 · GitHub
[go: up one dir, main page]

Skip to content

Commit b84faa4

Browse files
Merge branch '5.0'
* 5.0: [HttpClient] fix "undefined variable" [HttpClient] remove useless code in test [HttpClient] fix getting response content after its destructor throwed an HttpExceptionInterface [HttpClient] fix HttpClientDataCollector when handling canceled responses [Security] Fix exception name in doc comments
2 parents acc98b7 + b43d418 commit b84faa4

File tree

8 files changed

+38
-18
lines changed

8 files changed

+38
-18
lines changed

src/Symfony/Component/HttpClient/DataCollector/HttpClientDataCollector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ private function collectOnClient(TraceableHttpClient $client): array
119119
unset($info['http_method']);
120120
}
121121

122-
if ($trace['url'] === $info['url']) {
122+
if (($info['url'] ?? null) === $trace['url']) {
123123
unset($info['url']);
124124
}
125125

src/Symfony/Component/HttpClient/Response/CurlResponse.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\HttpClient\Chunk\InformationalChunk;
1717
use Symfony\Component\HttpClient\Exception\TransportException;
1818
use Symfony\Component\HttpClient\Internal\CurlClientState;
19+
use Symfony\Contracts\HttpClient\Exception\HttpExceptionInterface;
1920
use Symfony\Contracts\HttpClient\ResponseInterface;
2021

2122
/**
@@ -113,7 +114,7 @@ public function __construct(CurlClientState $multi, $ch, array $options = null,
113114
$this->initializer = static function (self $response) {
114115
$waitFor = curl_getinfo($ch = $response->handle, CURLINFO_PRIVATE);
115116

116-
return 'H' === $waitFor[0] || 'D' === $waitFor[0];
117+
return 'H' === $waitFor[0];
117118
};
118119

119120
// Schedule the request in a non-blocking way
@@ -174,17 +175,15 @@ public function __destruct()
174175
return; // Unused pushed response
175176
}
176177

177-
$waitFor = curl_getinfo($this->handle, CURLINFO_PRIVATE);
178-
179-
if ('C' === $waitFor[0] || '_' === $waitFor[0]) {
180-
$this->close();
181-
} elseif ('H' === $waitFor[0]) {
182-
$waitFor[0] = 'D'; // D = destruct
183-
curl_setopt($this->handle, CURLOPT_PRIVATE, $waitFor);
184-
}
185-
178+
$e = null;
186179
$this->doDestruct();
180+
} catch (HttpExceptionInterface $e) {
181+
throw $e;
187182
} finally {
183+
if ($e ?? false) {
184+
throw $e;
185+
}
186+
188187
$this->close();
189188

190189
if (!$this->multi->openHandles) {
@@ -304,7 +303,7 @@ private static function parseHeaderLine($ch, string $data, array &$info, array &
304303
{
305304
$waitFor = @curl_getinfo($ch, CURLINFO_PRIVATE) ?: '_0';
306305

307-
if ('H' !== $waitFor[0] && 'D' !== $waitFor[0]) {
306+
if ('H' !== $waitFor[0]) {
308307
return \strlen($data); // Ignore HTTP trailers
309308
}
310309

@@ -370,7 +369,7 @@ private static function parseHeaderLine($ch, string $data, array &$info, array &
370369
// Headers and redirects completed, time to get the response's content
371370
$multi->handlesActivity[$id][] = new FirstChunk();
372371

373-
if ('D' === $waitFor[0] || 'HEAD' === $info['http_method'] || \in_array($statusCode, [204, 304], true)) {
372+
if ('HEAD' === $info['http_method'] || \in_array($statusCode, [204, 304], true)) {
374373
$waitFor = '_0'; // no content expected
375374
$multi->handlesActivity[$id][] = null;
376375
$multi->handlesActivity[$id][] = null;

src/Symfony/Component/HttpClient/Response/NativeResponse.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\HttpClient\Chunk\FirstChunk;
1616
use Symfony\Component\HttpClient\Exception\TransportException;
1717
use Symfony\Component\HttpClient\Internal\NativeClientState;
18+
use Symfony\Contracts\HttpClient\Exception\HttpExceptionInterface;
1819
use Symfony\Contracts\HttpClient\ResponseInterface;
1920

2021
/**
@@ -84,11 +85,16 @@ public function getInfo(string $type = null)
8485

8586
public function __destruct()
8687
{
87-
$this->shouldBuffer = null;
88-
8988
try {
89+
$e = null;
9090
$this->doDestruct();
91+
} catch (HttpExceptionInterface $e) {
92+
throw $e;
9193
} finally {
94+
if ($e ?? false) {
95+
throw $e;
96+
}
97+
9298
$this->close();
9399

94100
// Clear the DNS cache when all requests completed

src/Symfony/Component/HttpClient/Response/ResponseTrait.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ private function checkStatusCode()
294294
*/
295295
private function doDestruct()
296296
{
297+
$this->shouldBuffer = true;
298+
297299
if ($this->initializer && null === $this->info['error']) {
298300
self::initialize($this);
299301
$this->checkStatusCode();

src/Symfony/Component/Messenger/Bridge/AmazonSqs/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"require": {
1919
"php": "^7.2.5",
2020
"symfony/http-client": "^4.3|5.0",
21-
"symfony/messenger": "^4.3|^5.0"
21+
"symfony/messenger": "^4.3|^5.0",
22+
"symfony/service-contracts": "^1.1|^2"
2223
},
2324
"require-dev": {
2425
"symfony/http-client-contracts": "^1.0|^2.0",

src/Symfony/Component/Security/Core/Exception/AuthenticationExpiredException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Symfony\Component\Security\Core\Exception;
1313

1414
/**
15-
* AuthenticationServiceException is thrown when an authenticated token becomes un-authenticated between requests.
15+
* AuthenticationExpiredException is thrown when an authenticated token becomes un-authenticated between requests.
1616
*
1717
* In practice, this is due to the User changing between requests (e.g. password changes),
1818
* causes the token to become un-authenticated.

src/Symfony/Component/Security/Guard/Provider/GuardAuthenticationProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function authenticate(TokenInterface $token)
8686
return $token;
8787
}
8888

89-
// this AccountStatusException causes the user to be logged out
89+
// this AccountExpiredException causes the user to be logged out
9090
throw new AuthenticationExpiredException();
9191
}
9292

src/Symfony/Contracts/HttpClient/Test/HttpClientTestCase.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,18 @@ public function testDestruct()
782782
$this->assertLessThan(4, $duration);
783783
}
784784

785+
public function testGetContentAfterDestruct()
786+
{
787+
$client = $this->getHttpClient(__FUNCTION__);
788+
789+
try {
790+
$client->request('GET', 'http://localhost:8057/404');
791+
$this->fail(ClientExceptionInterface::class.' expected');
792+
} catch (ClientExceptionInterface $e) {
793+
$this->assertSame('GET', $e->getResponse()->toArray(false)['REQUEST_METHOD']);
794+
}
795+
}
796+
785797
public function testProxy()
786798
{
787799
$client = $this->getHttpClient(__FUNCTION__);

0 commit comments

Comments
 (0)
0