8000 [HttpClient] add $response->cancel() by nicolas-grekas · Pull Request #31850 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpClient] add $response->cancel() #31850

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"psr/container": "^1.0",
"psr/link": "^1.0",
"psr/log": "~1.0",
"symfony/contracts": "^1.1.1",
"symfony/contracts": "^1.1.3",
"symfony/polyfill-ctype": "~1.8",
"symfony/polyfill-intl-icu": "~1.0",
"symfony/polyfill-intl-idn": "^1. 8000 10",
Expand Down
9 changes: 9 additions & 0 deletions src/Symfony/Component/HttpClient/Response/ResponseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,15 @@ public function toArray(bool $throw = true): array
return $content;
}

/**
* {@inheritdoc}
*/
public function cancel(): void
{
$this->info['error'] = 'Response has been canceled.';
$this->close();
}

/**
* Closes the response and all its network handles.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpClient/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"require": {
"php": "^7.1.3",
"psr/log": "^1.0",
"symfony/http-client-contracts": "^1.1",
"symfony/http-client-contracts": "^1.1.3",
"symfony/polyfill-php73": "^1.11"
},
"require-dev": {
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Contracts/HttpClient/ResponseInterface.php
Original file line number Diff line number Diff line change
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 src/Symfony/Contracts/HttpClient/Test/HttpClientTestCase.php
Original file line number Diff line number Diff line change
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