1
0
mirror of https://github.com/guzzle/guzzle.git synced 2025-02-24 10:03:27 +01:00

Ignore zeroed timeout with StreamHandler to use PHP default instead

Using \GuzzleHttp\Client without cURL being installed falls back to the
StreamHandler. As documented, guzzle uses a `timeout => 0` setting by
default, if that setting isn't explicitly passed as option. This value
is passed to the context of the stream, causing every request to fail
instantly as `timeout => 0` has a different meaning for streams.

Fixes #1487
This commit is contained in:
Andreas Fernandez 2016-06-05 11:52:24 +02:00
parent 6a37496c2b
commit 8abe196718
2 changed files with 18 additions and 1 deletions

View File

@ -346,7 +346,9 @@ class StreamHandler
private function add_timeout(RequestInterface $request, &$options, $value, &$params)
{
$options['http']['timeout'] = $value;
if ($value > 0) {
$options['http']['timeout'] = $value;
}
}
private function add_verify(RequestInterface $request, &$options, $value, &$params)

View File

@ -584,4 +584,19 @@ class StreamHandlerTest extends \PHPUnit_Framework_TestCase
$gotStats->getHandlerErrorData()
);
}
public function testStreamIgnoresZeroTimeout()
{
Server::flush();
Server::enqueue([new Psr7\Response(200)]);
$req = new Psr7\Request('GET', Server::$url);
$gotStats = null;
$handler = new StreamHandler();
$promise = $handler($req, [
'connect_timeout' => 10,
'timeout' => 0
]);
$response = $promise->wait();
$this->assertEquals(200, $response->getStatusCode());
}
}