1
0
mirror of https://github.com/guzzle/guzzle.git synced 2025-01-18 05:48:15 +01:00

Adding connect_timeout and removing curl from request options

This commit is contained in:
Michael Dowling 2013-06-07 18:43:57 -07:00
parent a20748c20e
commit dca26ad31c
4 changed files with 41 additions and 44 deletions

View File

@ -166,23 +166,24 @@ $response = Guzzle::post('http://guzzlephp.org', [
### Available request options: ### Available request options:
* "headers": Associative array of headers * headers: Associative array of headers
* "body": Body of a request, including an EntityBody, string, or array when sending POST requests. Setting a body for a * query: Associative array of query string values to add to the request
* body: Body of a request, including an EntityBody, string, or array when sending POST requests. Setting a body for a
GET request will set where the response body is downloaded. GET request will set where the response body is downloaded.
* "save_to": String, fopen resource, or EntityBody object used to store the body of the response * auth: Basic auth array where [0] is the username, [1] is the password, and [2] (optional) is the type
* "allow_redirects": Set to false to disable redirects * cookies: Associative array of cookies
* "auth": Basic auth array where [0] is the username, [1] is the password, and [2] (optional) is the type * allow_redirects: Set to false to disable redirects
* "query": Associative array of query string values to add to the request * save_to: String, fopen resource, or EntityBody object used to store the body of the response
* "cookies": Associative array of cookies * events: Associative array mapping event names to a closure or array of (priority, closure)
* "timeout": Float describing the timeout of the request in seconds * plugins: Array of plugins to add to the request
* "verify": Set to true to enable SSL cert validation (the default), false to disable, or supply the path to a CA * exceptions: Set to false to disable throwing exceptions on an HTTP level error (e.g. 404, 500, etc)
bundle to enable verification using a custom certificate. * timeout: Float describing the timeout of the request in seconds
* "proxy": Specify an HTTP proxy (e.g. "http://username:password@192.168.16.1:10") * connect_timeout: Float describing the number of seconds to wait while trying to connect. Use 0 to wait
* "curl": Associative array of CURL options to add to the request indefinitely.
* "events": Associative array mapping event names to a closure or array of (priority, closure) * verify: Set to true to enable SSL cert validation (the default), false to disable, or supply the path to a CA
* "plugins": Array of plugins to add to the request bundle to enable verification using a custom certificate.
* "debug": Set to true to display all data sent over the wire * proxy: Specify an HTTP proxy (e.g. "http://username:password@192.168.16.1:10")
* "exceptions": Set to false to disable throwing exceptions on an HTTP level error (e.g. 404, 500, etc) * debug: Set to true to display all data sent over the wire
These options can also be used when creating requests using a standard client: These options can also be used when creating requests using a standard client:

View File

@ -221,15 +221,6 @@ class RequestFactory implements RequestFactoryInterface
} }
} }
protected function visit_curl(RequestInterface $request, $value)
{
if (!is_array($value)) {
throw new InvalidArgumentException('curl value must be an array');
}
$request->getCurlOptions()->replace($value);
}
protected function visit_timeout(RequestInterface $request, $value) protected function visit_timeout(RequestInterface $request, $value)
{ {
$request->getCurlOptions()->set(CURLOPT_TIMEOUT_MS, $value * 1000); $request->getCurlOptions()->set(CURLOPT_TIMEOUT_MS, $value * 1000);
@ -310,4 +301,9 @@ class RequestFactory implements RequestFactoryInterface
{ {
$request->getCurlOptions()->set(CURLOPT_PROXY, $value); $request->getCurlOptions()->set(CURLOPT_PROXY, $value);
} }
protected function visit_connect_timeout(RequestInterface $request, $value)
{
$request->getCurlOptions()->set(CURLOPT_CONNECTTIMEOUT_MS, $value * 1000);
}
} }

View File

@ -68,21 +68,22 @@ interface RequestFactoryInterface
* @param RequestInterface $request Request to update * @param RequestInterface $request Request to update
* @param array $options Options to use with the request. Available options are: * @param array $options Options to use with the request. Available options are:
* "headers": Associative array of headers * "headers": Associative array of headers
* "body": Body of a request, including an EntityBody, string, or array when sending POST requests.
* "save_to": String, fopen resource, or EntityBody object used to store the body of the response
* "allow_redirects": Set to false to disable redirects
* "auth": Basic auth array where [0] is the username, [1] is the password, and [2] (optional) is the type
* "query": Associative array of query string values to add to the request * "query": Associative array of query string values to add to the request
* "body": Body of a request, including an EntityBody, string, or array when sending POST requests.
* "auth": Basic auth array where [0] is the username, [1] is the password, and [2] (optional) is the type
* "cookies": Associative array of cookies * "cookies": Associative array of cookies
* "timeout": Float describing the timeout of the request in seconds * "allow_redirects": Set to false to disable redirects
* "verify": Set to true to enable SSL cert validation (the default), false to disable, or supply the path to * "save_to": String, fopen resource, or EntityBody object used to store the body of the response
* a CA bundle to enable verification using a custom certificate.
* "proxy": Specify an HTTP proxy (e.g. "http://username:password@192.168.16.1:10")
* "curl": Associative array of CURL options to add to the request
* "events": Associative array mapping event names to a closure or array of (priority, closure) * "events": Associative array mapping event names to a closure or array of (priority, closure)
* "plugins": Array of plugins to add to the request * "plugins": Array of plugins to add to the request
* "debug": Set to true to display all data sent over the wire
* "exceptions": Set to false to disable throwing exceptions on an HTTP level error (e.g. 404, 500, etc) * "exceptions": Set to false to disable throwing exceptions on an HTTP level error (e.g. 404, 500, etc)
* "timeout": Float describing the timeout of the request in seconds
* "connect_timeout": Float describing the number of seconds to wait while trying to connect. Use 0 to wait
* indefinitely.
* "verify": Set to true to enable SSL cert validation (the default), false to disable, or supply the path
* to a CA bundle to enable verification using a custom certificate.
* "proxy": Specify an HTTP proxy (e.g. "http://username:password@192.168.16.1:10")
* "debug": Set to true to display all data sent over the wire
*/ */
public function applyOptions(RequestInterface $request, array $options = array()); public function applyOptions(RequestInterface $request, array $options = array());
} }

View File

@ -361,14 +361,6 @@ class HttpRequestFactoryTest extends \Guzzle\Tests\GuzzleTestCase
$this->assertEquals('Bar', $request->getQuery()->get('Foo')); $this->assertEquals('Bar', $request->getQuery()->get('Foo'));
} }
public function testCanAddCurl()
{
$request = RequestFactory::getInstance()->create('GET', 'http://foo.com', array(), null, array(
'curl' => array(CURLOPT_ENCODING => '*')
));
$this->assertEquals('*', $request->getCurlOptions()->get(CURLOPT_ENCODING));
}
public function testCanAddAuth() public function testCanAddAuth()
{ {
$request = RequestFactory::getInstance()->create('GET', 'http://foo.com', array(), null, array( $request = RequestFactory::getInstance()->create('GET', 'http://foo.com', array(), null, array(
@ -476,6 +468,13 @@ class HttpRequestFactoryTest extends \Guzzle\Tests\GuzzleTestCase
$this->assertEquals(1500, $request->getCurlOptions()->get(CURLOPT_TIMEOUT_MS)); $this->assertEquals(1500, $request->getCurlOptions()->get(CURLOPT_TIMEOUT_MS));
} }
public function testCanSetConnectTimeoutOption()
{
$client = new Client();
$request = $client->get('/', array(), array('connect_timeout' => 1.5));
$this->assertEquals(1500, $request->getCurlOptions()->get(CURLOPT_CONNECTTIMEOUT_MS));
}
public function testCanSetDebug() public function testCanSetDebug()
{ {
$client = new Client(); $client = new Client();
@ -520,7 +519,7 @@ class HttpRequestFactoryTest extends \Guzzle\Tests\GuzzleTestCase
public function inputValidation() public function inputValidation()
{ {
return array_map(function ($option) { return array($option); }, array( return array_map(function ($option) { return array($option); }, array(
'headers', 'query', 'cookies', 'auth', 'curl', 'events', 'plugins' 'headers', 'query', 'cookies', 'auth', 'events', 'plugins'
)); ));
} }