Skip to content

Commit 852fb36

Browse files
committed
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 ------- 549930e [HttpClient] add $response->cancel()
2 parents 9ce3ff3 + 549930e commit 852fb36

File tree

5 files changed

+29
-0
lines changed

5 files changed

+29
-0
lines changed

UPGRADE-4.4.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ DependencyInjection
2525
factory: ['@factory_service', method]
2626
```
2727
28+
HttpClient
29+
----------
30+
31+
* Added method `cancel()` to `ResponseInterface`
32+
2833
Messenger
2934
---------
3035

UPGRADE-5.0.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,11 @@ FrameworkBundle
221221
* Removed the "Psr\SimpleCache\CacheInterface" / "cache.app.simple" service, use "Symfony\Contracts\Cache\CacheInterface" / "cache.app" instead.
222222
* Removed support for `templating` engine in `TemplateController`, use Twig instead
223223

224+
HttpClient
225+
----------
226+
227+
* Added method `cancel()` to `ResponseInterface`
228+
224229
HttpFoundation
225230
--------------
226231

src/Symfony/Component/HttpClient/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
4.4.0
5+
-----
6+
7+
* added `$response->cancel()`
8+
49
4.3.0
510
-----
611

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,15 @@ public function toArray(bool $throw = true): array
169169
return $content;
170170
}
171171

172+
/**
173+
* {@inheritdoc}
174+
*/
175+
public function cancel(): void
176+
{
177+
$this->info['error'] = 'Response has been canceled.';
178+
$this->close();
179+
}
180+
172181
/**
173182
* Closes the response and all its network handles.
174183
*/

src/Symfony/Contracts/HttpClient/ResponseInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ public function getContent(bool $throw = true): string;
7171
*/
7272
public function toArray(bool $throw = true): array;
7373

74+
/**
75+
* Cancels the response.
76+
*/
77+
public function cancel(): void;
78+
7479
/**
7580
* Returns info coming from the transport layer.
7681
*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy