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:
parent
a20748c20e
commit
dca26ad31c
33
README.md
33
README.md
@ -166,23 +166,24 @@ $response = Guzzle::post('http://guzzlephp.org', [
|
||||
|
||||
### Available request options:
|
||||
|
||||
* "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
|
||||
* headers: Associative array of headers
|
||||
* 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.
|
||||
* "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
|
||||
* "cookies": Associative array of cookies
|
||||
* "timeout": Float describing the timeout of the request in seconds
|
||||
* "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")
|
||||
* "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)
|
||||
* "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)
|
||||
* auth: Basic auth array where [0] is the username, [1] is the password, and [2] (optional) is the type
|
||||
* cookies: Associative array of cookies
|
||||
* allow_redirects: Set to false to disable redirects
|
||||
* save_to: String, fopen resource, or EntityBody object used to store the body of the response
|
||||
* events: Associative array mapping event names to a closure or array of (priority, closure)
|
||||
* plugins: Array of plugins to add to the request
|
||||
* 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
|
||||
|
||||
These options can also be used when creating requests using a standard client:
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
$request->getCurlOptions()->set(CURLOPT_TIMEOUT_MS, $value * 1000);
|
||||
@ -310,4 +301,9 @@ class RequestFactory implements RequestFactoryInterface
|
||||
{
|
||||
$request->getCurlOptions()->set(CURLOPT_PROXY, $value);
|
||||
}
|
||||
|
||||
protected function visit_connect_timeout(RequestInterface $request, $value)
|
||||
{
|
||||
$request->getCurlOptions()->set(CURLOPT_CONNECTTIMEOUT_MS, $value * 1000);
|
||||
}
|
||||
}
|
||||
|
@ -68,21 +68,22 @@ interface RequestFactoryInterface
|
||||
* @param RequestInterface $request Request to update
|
||||
* @param array $options Options to use with the request. Available options are:
|
||||
* "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
|
||||
* "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
|
||||
* "timeout": Float describing the timeout of the request in seconds
|
||||
* "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")
|
||||
* "curl": Associative array of CURL options to add to the request
|
||||
* "allow_redirects": Set to false to disable redirects
|
||||
* "save_to": String, fopen resource, or EntityBody object used to store the body of the response
|
||||
* "events": Associative array mapping event names to a closure or array of (priority, closure)
|
||||
* "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)
|
||||
* "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());
|
||||
}
|
||||
|
@ -361,14 +361,6 @@ class HttpRequestFactoryTest extends \Guzzle\Tests\GuzzleTestCase
|
||||
$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()
|
||||
{
|
||||
$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));
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
$client = new Client();
|
||||
@ -520,7 +519,7 @@ class HttpRequestFactoryTest extends \Guzzle\Tests\GuzzleTestCase
|
||||
public function inputValidation()
|
||||
{
|
||||
return array_map(function ($option) { return array($option); }, array(
|
||||
'headers', 'query', 'cookies', 'auth', 'curl', 'events', 'plugins'
|
||||
'headers', 'query', 'cookies', 'auth', 'events', 'plugins'
|
||||
));
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user