feature #31831 [HttpClient] add $response->cancel() (nicolas-grekas)
This PR was merged into the 4.4 branch.
Discussion
----------
[HttpClient] add $response->cancel()
| Q | A
| ------------- | ---
| Branch? | 4.4
| Bug fix? | no
| New feature? | yes
| BC breaks? | yes
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
(BC break allowed by the `@experimental` annotation)
Canceling a response is already possible but requires registering a progress function and throwing an exception from it. This new method aims at making this much simpler.
/cc @jderusse as we discussed this on Slack.
Commits
-------
549930e820
[HttpClient] add $response->cancel()
This commit is contained in:
commit
852fb36101
|
@ -25,6 +25,11 @@ DependencyInjection
|
|||
factory: ['@factory_service', method]
|
||||
```
|
||||
|
||||
HttpClient
|
||||
----------
|
||||
|
||||
* Added method `cancel()` to `ResponseInterface`
|
||||
|
||||
Messenger
|
||||
---------
|
||||
|
||||
|
|
|
@ -221,6 +221,11 @@ FrameworkBundle
|
|||
* Removed the "Psr\SimpleCache\CacheInterface" / "cache.app.simple" service, use "Symfony\Contracts\Cache\CacheInterface" / "cache.app" instead.
|
||||
* Removed support for `templating` engine in `TemplateController`, use Twig instead
|
||||
|
||||
HttpClient
|
||||
----------
|
||||
|
||||
* Added method `cancel()` to `ResponseInterface`
|
||||
|
||||
HttpFoundation
|
||||
--------------
|
||||
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
CHANGELOG
|
||||
=========
|
||||
|
||||
4.4.0
|
||||
-----
|
||||
|
||||
* added `$response->cancel()`
|
||||
|
||||
4.3.0
|
||||
-----
|
||||
|
||||
|
|
|
@ -169,6 +169,15 @@ trait ResponseTrait
|
|||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function cancel(): void
|
||||
{
|
||||
$this->info['error'] = 'Response has been canceled.';
|
||||
$this->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the response and all its network handles.
|
||||
*/
|
||||
|
|
|
@ -71,6 +71,11 @@ interface ResponseInterface
|
|||
*/
|
||||
public function toArray(bool $throw = true): array;
|
||||
|
||||
/**
|
||||
* Cancels the response.
|
||||
*/
|
||||
public function cancel(): void;
|
||||
|
||||
/**
|
||||
* Returns info coming from the transport layer.
|
||||
*
|
||||
|
|
Reference in New Issue