Skip to content

Commit 4f45d0e

Browse files
[HttpClient] add $response->cancel()
1 parent c87486c commit 4f45d0e

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

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
*

Test/HttpClientTestCase.php

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

484+
public function testCancel()
485+
{
486+
$client = $this->getHttpClient(__FUNCTION__);
487+
$response = $client->request('GET', 'http://localhost:8057/timeout-header');
488+
489+
$response->cancel();
490+
$this->expectException(TransportExceptionInterface::class);
491+
$response->getHeaders();
492+
}
493+
484494
public function testOnProgressCancel()
485495
{
486496
$client = $this->getHttpClient(__FUNCTION__);

0 commit comments

Comments
 (0)