Skip to content

Commit 26ce72f

Browse files
Toflarnicolas-grekas
authored andcommitted
[HttpClient] Add a canceled state to the ResponseInterface
1 parent aaf8b45 commit 26ce72f

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

HttpClient/ResponseInterface.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,16 @@ public function cancel(): void;
8888
* another, as the request/response progresses.
8989
*
9090
* The following info MUST be returned:
91-
* - response_headers - an array modelled after the special $http_response_header variable
92-
* - redirect_count - the number of redirects followed while executing the request
93-
* - redirect_url - the resolved location of redirect responses, null otherwise
94-
* - start_time - the time when the request was sent or 0.0 when it's pending
95-
* - http_method - the HTTP verb of the last request
96-
* - http_code - the last response code or 0 when it is not known yet
97-
* - error - the error message when the transfer was aborted, null otherwise
98-
* - user_data - the value of the "user_data" request option, null if not set
99-
* - url - the last effective URL of the request
91+
* - canceled (bool) - true if the response was canceled using ResponseInterface::cancel(), false otherwise
92+
* - error (string|null) - the error message when the transfer was aborted, null otherwise
93+
* - http_code (int) - the last response code or 0 when it is not known yet
94+
* - http_method (string) - the HTTP verb of the last request
95+
* - redirect_count (int) - the number of redirects followed while executing the request
96+
* - redirect_url (string|null) - the resolved location of redirect responses, null otherwise
97+
* - response_headers (array) - an array modelled after the special $http_response_header variable
98+
* - start_time (float) - the time when the request was sent or 0.0 when it's pending
99+
* - url (string) - the last effective URL of the request
100+
* - user_data (mixed|null) - the value of the "user_data" request option, null if not set
100101
*
101102
* When the "capture_peer_cert_chain" option is true, the "peer_certificate_chain"
102103
* attribute SHOULD list the peer certificates as an array of OpenSSL X.509 resources.

HttpClient/Test/HttpClientTestCase.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,17 @@ public function testCancel()
515515
$response->getHeaders();
516516
}
517517

518+
public function testInfoOnCanceledResponse()
519+
{
520+
$client = $this->getHttpClient(__FUNCTION__);
521+
522+
$response = $client->request('GET', 'http://localhost:8057/timeout-header');
523+
524+
$this->assertFalse($response->getInfo('canceled'));
525+
$response->cancel();
526+
$this->assertTrue($response->getInfo('canceled'));
527+
}
528+
518529
public function testCancelInStream()
519530
{
520531
$client = $this->getHttpClient(__FUNCTION__);

0 commit comments

Comments
 (0)