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
This commit is contained in:
commit
b84faa4ee8
@ -119,7 +119,7 @@ final class HttpClientDataCollector extends DataCollector implements LateDataCol
|
|||||||
unset($info['http_method']);
|
unset($info['http_method']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($trace['url'] === $info['url']) {
|
if (($info['url'] ?? null) === $trace['url']) {
|
||||||
unset($info['url']);
|
unset($info['url']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ use Symfony\Component\HttpClient\Chunk\FirstChunk;
|
|||||||
use Symfony\Component\HttpClient\Chunk\InformationalChunk;
|
use Symfony\Component\HttpClient\Chunk\InformationalChunk;
|
||||||
use Symfony\Component\HttpClient\Exception\TransportException;
|
use Symfony\Component\HttpClient\Exception\TransportException;
|
||||||
use Symfony\Component\HttpClient\Internal\CurlClientState;
|
use Symfony\Component\HttpClient\Internal\CurlClientState;
|
||||||
|
use Symfony\Contracts\HttpClient\Exception\HttpExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\ResponseInterface;
|
use Symfony\Contracts\HttpClient\ResponseInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -113,7 +114,7 @@ final class CurlResponse implements ResponseInterface
|
|||||||
$this->initializer = static function (self $response) {
|
$this->initializer = static function (self $response) {
|
||||||
$waitFor = curl_getinfo($ch = $response->handle, CURLINFO_PRIVATE);
|
$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
|
// Schedule the request in a non-blocking way
|
||||||
@ -174,17 +175,15 @@ final class CurlResponse implements ResponseInterface
|
|||||||
return; // Unused pushed response
|
return; // Unused pushed response
|
||||||
}
|
}
|
||||||
|
|
||||||
$waitFor = curl_getinfo($this->handle, CURLINFO_PRIVATE);
|
$e = null;
|
||||||
|
$this->doDestruct();
|
||||||
if ('C' === $waitFor[0] || '_' === $waitFor[0]) {
|
} catch (HttpExceptionInterface $e) {
|
||||||
$this->close();
|
throw $e;
|
||||||
} elseif ('H' === $waitFor[0]) {
|
} finally {
|
||||||
$waitFor[0] = 'D'; // D = destruct
|
if ($e ?? false) {
|
||||||
curl_setopt($this->handle, CURLOPT_PRIVATE, $waitFor);
|
throw $e;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->doDestruct();
|
|
||||||
} finally {
|
|
||||||
$this->close();
|
$this->close();
|
||||||
|
|
||||||
if (!$this->multi->openHandles) {
|
if (!$this->multi->openHandles) {
|
||||||
@ -304,7 +303,7 @@ final class CurlResponse implements ResponseInterface
|
|||||||
{
|
{
|
||||||
$waitFor = @curl_getinfo($ch, CURLINFO_PRIVATE) ?: '_0';
|
$waitFor = @curl_getinfo($ch, CURLINFO_PRIVATE) ?: '_0';
|
||||||
|
|
||||||
if ('H' !== $waitFor[0] && 'D' !== $waitFor[0]) {
|
if ('H' !== $waitFor[0]) {
|
||||||
return \strlen($data); // Ignore HTTP trailers
|
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
|
// Headers and redirects completed, time to get the response's content
|
||||||
$multi->handlesActivity[$id][] = new FirstChunk();
|
$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
|
$waitFor = '_0'; // no content expected
|
||||||
$multi->handlesActivity[$id][] = null;
|
$multi->handlesActivity[$id][] = null;
|
||||||
$multi->handlesActivity[$id][] = null;
|
$multi->handlesActivity[$id][] = null;
|
||||||
|
@ -15,6 +15,7 @@ use Psr\Log\LoggerInterface;
|
|||||||
use Symfony\Component\HttpClient\Chunk\FirstChunk;
|
use Symfony\Component\HttpClient\Chunk\FirstChunk;
|
||||||
use Symfony\Component\HttpClient\Exception\TransportException;
|
use Symfony\Component\HttpClient\Exception\TransportException;
|
||||||
use Symfony\Component\HttpClient\Internal\NativeClientState;
|
use Symfony\Component\HttpClient\Internal\NativeClientState;
|
||||||
|
use Symfony\Contracts\HttpClient\Exception\HttpExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\ResponseInterface;
|
use Symfony\Contracts\HttpClient\ResponseInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -84,11 +85,16 @@ final class NativeResponse implements ResponseInterface
|
|||||||
|
|
||||||
public function __destruct()
|
public function __destruct()
|
||||||
{
|
{
|
||||||
$this->shouldBuffer = null;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
$e = null;
|
||||||
$this->doDestruct();
|
$this->doDestruct();
|
||||||
|
} catch (HttpExceptionInterface $e) {
|
||||||
|
throw $e;
|
||||||
} finally {
|
} finally {
|
||||||
|
if ($e ?? false) {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
|
||||||
$this->close();
|
$this->close();
|
||||||
|
|
||||||
// Clear the DNS cache when all requests completed
|
// Clear the DNS cache when all requests completed
|
||||||
|
@ -294,6 +294,8 @@ trait ResponseTrait
|
|||||||
*/
|
*/
|
||||||
private function doDestruct()
|
private function doDestruct()
|
||||||
{
|
{
|
||||||
|
$this->shouldBuffer = true;
|
||||||
|
|
||||||
if ($this->initializer && null === $this->info['error']) {
|
if ($this->initializer && null === $this->info['error']) {
|
||||||
self::initialize($this);
|
self::initialize($this);
|
||||||
$this->checkStatusCode();
|
$this->checkStatusCode();
|
||||||
|
@ -18,7 +18,8 @@
|
|||||||
"require": {
|
"require": {
|
||||||
"php": "^7.2.5",
|
"php": "^7.2.5",
|
||||||
"symfony/http-client": "^4.3|5.0",
|
"symfony/http-client": "^4.3|5.0",
|
||||||
"symfony/messenger": "^4.3|^5.0"
|
"symfony/messenger": "^4.3|^5.0",
|
||||||
|
"symfony/service-contracts": "^1.1|^2"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"symfony/http-client-contracts": "^1.0|^2.0",
|
"symfony/http-client-contracts": "^1.0|^2.0",
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
namespace Symfony\Component\Security\Core\Exception;
|
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),
|
* In practice, this is due to the User changing between requests (e.g. password changes),
|
||||||
* causes the token to become un-authenticated.
|
* causes the token to become un-authenticated.
|
||||||
|
@ -86,7 +86,7 @@ class GuardAuthenticationProvider implements AuthenticationProviderInterface
|
|||||||
return $token;
|
return $token;
|
||||||
}
|
}
|
||||||
|
|
||||||
// this AccountStatusException causes the user to be logged out
|
// this AccountExpiredException causes the user to be logged out
|
||||||
throw new AuthenticationExpiredException();
|
throw new AuthenticationExpiredException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -782,6 +782,18 @@ abstract class HttpClientTestCase extends TestCase
|
|||||||
$this->assertLessThan(4, $duration);
|
$this->assertLessThan(4, $duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetContentAfterDestruct()
|
||||||
|
{
|
||||||
|
$client = $this->getHttpClient(__FUNCTION__);
|
||||||
|
|
||||||
|
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()
|
public function testProxy()
|
||||||
{
|
{
|
||||||
$client = $this->getHttpClient(__FUNCTION__);
|
$client = $this->getHttpClient(__FUNCTION__);
|
||||||
|
Reference in New Issue
Block a user