Skip to content

Commit

Permalink
[HttpClient] add $response->cancel()
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Jun 4, 2019
1 parent c87486c commit 4f45d0e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ResponseInterface.php
Expand Up @@ -71,6 +71,11 @@ public function getContent(bool $throw = true): string;
*/
public function toArray(bool $throw = true): array;

/**
* Cancels the response.
*/
public function cancel(): void;

/**
* Returns info coming from the transport layer.
*
Expand Down
10 changes: 10 additions & 0 deletions Test/HttpClientTestCase.php
Expand Up @@ -481,6 +481,16 @@ public function testPostCallback()
$this->assertSame(['foo' => '0123456789', 'REQUEST_METHOD' => 'POST'], $response->toArray());
}

public function testCancel()
{
$client = $this->getHttpClient(__FUNCTION__);
$response = $client->request('GET', 'http://localhost:8057/timeout-header');

$response->cancel();
$this->expectException(TransportExceptionInterface::class);
$response->getHeaders();
}

public function testOnProgressCancel()
{
$client = $this->getHttpClient(__FUNCTION__);
Expand Down

0 comments on commit 4f45d0e

Please sign in to comment.