[HttpClient] add $response->cancel()
This commit is contained in:
parent
40076b98bf
commit
c402418723
|
@ -26,7 +26,7 @@
|
||||||
"psr/container": "^1.0",
|
"psr/container": "^1.0",
|
||||||
"psr/link": "^1.0",
|
"psr/link": "^1.0",
|
||||||
"psr/log": "~1.0",
|
"psr/log": "~1.0",
|
||||||
"symfony/contracts": "^1.1.1",
|
"symfony/contracts": "^1.1.3",
|
||||||
"symfony/polyfill-ctype": "~1.8",
|
"symfony/polyfill-ctype": "~1.8",
|
||||||
"symfony/polyfill-intl-icu": "~1.0",
|
"symfony/polyfill-intl-icu": "~1.0",
|
||||||
"symfony/polyfill-intl-idn": "^1.10",
|
"symfony/polyfill-intl-idn": "^1.10",
|
||||||
|
|
|
@ -169,6 +169,15 @@ trait ResponseTrait
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function cancel(): void
|
||||||
|
{
|
||||||
|
$this->info['error'] = 'Response has been canceled.';
|
||||||
|
$this->close();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes the response and all its network handles.
|
* Closes the response and all its network handles.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^7.1.3",
|
"php": "^7.1.3",
|
||||||
"psr/log": "^1.0",
|
"psr/log": "^1.0",
|
||||||
"symfony/http-client-contracts": "^1.1",
|
"symfony/http-client-contracts": "^1.1.3",
|
||||||
"symfony/polyfill-php73": "^1.11"
|
"symfony/polyfill-php73": "^1.11"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
|
|
|
@ -71,6 +71,11 @@ interface ResponseInterface
|
||||||
*/
|
*/
|
||||||
public function toArray(bool $throw = true): array;
|
public function toArray(bool $throw = true): array;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cancels the response.
|
||||||
|
*/
|
||||||
|
public function cancel(): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns info coming from the transport layer.
|
* Returns info coming from the transport layer.
|
||||||
*
|
*
|
||||||
|
|
|
@ -481,6 +481,16 @@ abstract class HttpClientTestCase extends TestCase
|
||||||
$this->assertSame(['foo' => '0123456789', 'REQUEST_METHOD' => 'POST'], $response->toArray());
|
$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()
|
public function testOnProgressCancel()
|
||||||
{
|
{
|
||||||
$client = $this->getHttpClient(__FUNCTION__);
|
$client = $this->getHttpClient(__FUNCTION__);
|
||||||
|
|
Reference in New Issue