Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd20a0c3

Browse files
[HttpClient] add TimeoutExceptionInterface
1 parent2b554d8 commitd20a0c3

File tree

7 files changed

+68
-7
lines changed

7 files changed

+68
-7
lines changed

‎src/Symfony/Component/HttpClient/Chunk/ErrorChunk.php‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespaceSymfony\Component\HttpClient\Chunk;
1313

14+
useSymfony\Component\HttpClient\Exception\TimeoutException;
1415
useSymfony\Component\HttpClient\Exception\TransportException;
1516
useSymfony\Contracts\HttpClient\ChunkInterface;
1617

@@ -61,7 +62,7 @@ public function isTimeout(): bool
6162
publicfunctionisFirst():bool
6263
{
6364
$this->didThrow =true;
64-
thrownewTransportException($this->errorMessage,0,$this->error);
65+
thrownull !==$this->error ?newTransportException($this->errorMessage,0,$this->error) :newTimeoutException($this->errorMessage);
6566
}
6667

6768
/**
@@ -70,7 +71,7 @@ public function isFirst(): bool
7071
publicfunctionisLast():bool
7172
{
7273
$this->didThrow =true;
73-
thrownewTransportException($this->errorMessage,0,$this->error);
74+
thrownull !==$this->error ?newTransportException($this->errorMessage,0,$this->error) :newTimeoutException($this->errorMessage);
7475
}
7576

7677
/**
@@ -79,7 +80,7 @@ public function isLast(): bool
7980
publicfunctiongetInformationalStatus(): ?array
8081
{
8182
$this->didThrow =true;
82-
thrownewTransportException($this->errorMessage,0,$this->error);
83+
thrownull !==$this->error ?newTransportException($this->errorMessage,0,$this->error) :newTimeoutException($this->errorMessage);
8384
}
8485

8586
/**
@@ -88,7 +89,7 @@ public function getInformationalStatus(): ?array
8889
publicfunctiongetContent():string
8990
{
9091
$this->didThrow =true;
91-
thrownewTransportException($this->errorMessage,0,$this->error);
92+
thrownull !==$this->error ?newTransportException($this->errorMessage,0,$this->error) :newTimeoutException($this->errorMessage);
9293
}
9394

9495
/**
@@ -119,7 +120,7 @@ public function __destruct()
119120
{
120121
if (!$this->didThrow) {
121122
$this->didThrow =true;
122-
thrownewTransportException($this->errorMessage,0,$this->error);
123+
thrownull !==$this->error ?newTransportException($this->errorMessage,0,$this->error) :newTimeoutException($this->errorMessage);
123124
}
124125
}
125126
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\HttpClient\Exception;
13+
14+
useSymfony\Contracts\HttpClient\Exception\TimeoutExceptionInterface;
15+
16+
/**
17+
* @author Nicolas Grekas <p@tchwork.com>
18+
*/
19+
finalclass TimeoutExceptionextends TransportExceptionimplements TimeoutExceptionInterface
20+
{
21+
}

‎src/Symfony/Component/HttpClient/Exception/TransportException.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
/**
1717
* @author Nicolas Grekas <p@tchwork.com>
1818
*/
19-
finalclass TransportExceptionextends \RuntimeExceptionimplements TransportExceptionInterface
19+
class TransportExceptionextends \RuntimeExceptionimplements TransportExceptionInterface
2020
{
2121
}

‎src/Symfony/Component/HttpClient/Tests/MockHttpClientTest.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ protected function getHttpClient(string $testCase): HttpClientInterface
253253

254254
case'testTimeoutOnStream':
255255
case'testUncheckedTimeoutThrows':
256+
case'testTimeoutIsNotAFatalError':
256257
$body = ['<1>','','<2>'];
257258
$responses[] =newMockResponse($body, ['response_headers' =>$headers]);
258259
break;

‎src/Symfony/Component/HttpClient/composer.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"require": {
2424
"php":"^7.2.5",
2525
"psr/log":"^1.0",
26-
"symfony/http-client-contracts":"^1.1.8|^2",
26+
"symfony/http-client-contracts":"^2.1.1",
2727
"symfony/polyfill-php73":"^1.11",
2828
"symfony/polyfill-php80":"^1.15",
2929
"symfony/service-contracts":"^1.0|^2"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Contracts\HttpClient\Exception;
13+
14+
/**
15+
* When an idle timeout occurs.
16+
*
17+
* @author Nicolas Grekas <p@tchwork.com>
18+
*/
19+
interface TimeoutExceptionInterfaceextends TransportExceptionInterface
20+
{
21+
}

‎src/Symfony/Contracts/HttpClient/Test/HttpClientTestCase.php‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
usePHPUnit\Framework\TestCase;
1515
useSymfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
1616
useSymfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
17+
useSymfony\Contracts\HttpClient\Exception\TimeoutExceptionInterface;
1718
useSymfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
1819
useSymfony\Contracts\HttpClient\HttpClientInterface;
1920

@@ -741,6 +742,22 @@ public function testTimeoutOnAccess()
741742
$response->getHeaders();
742743
}
743744

745+
publicfunctiontestTimeoutIsNotAFatalError()
746+
{
747+
$client =$this->getHttpClient(__FUNCTION__);
748+
$response =$client->request('GET','http://localhost:8057/timeout-body', [
749+
'timeout' =>0.4,
750+
]);
751+
752+
try {
753+
$response->getContent();
754+
$this->fail(TimeoutExceptionInterface::class.' expected');
755+
}catch (TimeoutExceptionInterface$e) {
756+
}
757+
758+
$this->assertSame('<1><2>',$response->getContent());
759+
}
760+
744761
publicfunctiontestTimeoutOnStream()
745762
{
746763
usleep(300000);// wait for the previous test to release the server

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp