From 827e29b8494d33f367330682afb4be71d1d870e9 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 3 Jun 2019 19:56:51 +0200 Subject: [PATCH] [HttpClient] add $response->cancel() --- HttpClient/ResponseInterface.php | 5 +++++ HttpClient/Test/HttpClientTestCase.php | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/HttpClient/ResponseInterface.php b/HttpClient/ResponseInterface.php index 6751184..a7e01be 100644 --- a/HttpClient/ResponseInterface.php +++ b/HttpClient/ResponseInterface.php @@ -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. * diff --git a/HttpClient/Test/HttpClientTestCase.php b/HttpClient/Test/HttpClientTestCase.php index b898ba5..a5ea76f 100644 --- a/HttpClient/Test/HttpClientTestCase.php +++ b/HttpClient/Test/HttpClientTestCase.php @@ -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__);