minor #32557 [HttpClient] make toStream() throw by default (nicolas-grekas)
This PR was merged into the 4.4 branch.
Discussion
----------
[HttpClient] make toStream() throw by default
| Q | A
| ------------- | ---
| Branch? | 4.4
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
For consistency with ->getHeaders()/->getContent().
Commits
-------
90e46ab13b
[HttpClient] make toStream() throw by default
This commit is contained in:
commit
af309b0acf
@ -92,7 +92,7 @@ final class Psr18Client implements ClientInterface, RequestFactoryInterface, Str
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$body = isset(class_uses($response)[ResponseTrait::class]) ? $response->toStream() : StreamWrapper::createResource($response, $this->client);
|
$body = isset(class_uses($response)[ResponseTrait::class]) ? $response->toStream(false) : StreamWrapper::createResource($response, $this->client);
|
||||||
|
|
||||||
return $psrResponse->withBody($this->streamFactory->createStreamFromResource($body));
|
return $psrResponse->withBody($this->streamFactory->createStreamFromResource($body));
|
||||||
} catch (TransportExceptionInterface $e) {
|
} catch (TransportExceptionInterface $e) {
|
||||||
|
@ -21,6 +21,10 @@ use Symfony\Component\HttpClient\Exception\RedirectionException;
|
|||||||
use Symfony\Component\HttpClient\Exception\ServerException;
|
use Symfony\Component\HttpClient\Exception\ServerException;
|
||||||
use Symfony\Component\HttpClient\Exception\TransportException;
|
use Symfony\Component\HttpClient\Exception\TransportException;
|
||||||
use Symfony\Component\HttpClient\Internal\ClientState;
|
use Symfony\Component\HttpClient\Internal\ClientState;
|
||||||
|
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||||
|
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
||||||
|
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
||||||
|
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements the common logic for response classes.
|
* Implements the common logic for response classes.
|
||||||
@ -182,11 +186,16 @@ trait ResponseTrait
|
|||||||
* Casts the response to a PHP stream resource.
|
* Casts the response to a PHP stream resource.
|
||||||
*
|
*
|
||||||
* @return resource|null
|
* @return resource|null
|
||||||
|
*
|
||||||
|
* @throws TransportExceptionInterface When a network error occurs
|
||||||
|
* @throws RedirectionExceptionInterface On a 3xx when $throw is true and the "max_redirects" option has been reached
|
||||||
|
* @throws ClientExceptionInterface On a 4xx when $throw is true
|
||||||
|
* @throws ServerExceptionInterface On a 5xx when $throw is true
|
||||||
*/
|
*/
|
||||||
public function toStream()
|
public function toStream(bool $throw = true)
|
||||||
{
|
{
|
||||||
// Ensure headers arrived
|
// Ensure headers arrived
|
||||||
$this->getStatusCode();
|
$this->getHeaders($throw);
|
||||||
|
|
||||||
return StreamWrapper::createResource($this, null, $this->content, $this->handle && 'stream' === get_resource_type($this->handle) ? $this->handle : null);
|
return StreamWrapper::createResource($this, null, $this->content, $this->handle && 'stream' === get_resource_type($this->handle) ? $this->handle : null);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user