Skip to content

Commit aa4bb76

Browse files
committed
bug #31850 [HttpClient] add $response->cancel() (nicolas-grekas)
This PR was merged into the 4.3 branch. Discussion ---------- [HttpClient] add $response->cancel() | Q | A | ------------- | --- | Branch? | 4.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | symfony/symfony-docs#11668 An alternative to #31845 and #31842. Same as #31831 but considered as a bug fix (at the Contracts level), thus for 4.3. I think we're early enough since 4.3/1.1 to do it. That will save us some headaches in the short term. Commits ------- c402418723 [HttpClient] add $response->cancel()
2 parents 996a11d + 827e29b commit aa4bb76

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

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
*

HttpClient/Test/HttpClientTestCase.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,16 @@ public function testPostCallback()
495495
$this->assertSame(['foo' => '0123456789', 'REQUEST_METHOD' => 'POST'], $response->toArray());
496496
}
497497

498+
public function testCancel()
499+
{
500+
$client = $this->getHttpClient(__FUNCTION__);
501+
$response = $client->request('GET', 'http://localhost:8057/timeout-header');
502+
503+
$response->cancel();
504+
$this->expectException(TransportExceptionInterface::class);
505+
$response->getHeaders();
506+
}
507+
498508
public function testOnProgressCancel()
499509
{
500510
$client = $this->getHttpClient(__FUNCTION__);

0 commit comments

Comments
 (0)