1
0
mirror of https://github.com/guzzle/guzzle.git synced 2025-02-25 02:22:57 +01:00

Adding a proxy option to requests. Adding a save_to option. Allowing the auth value to accept an optional auth scheme

This commit is contained in:
Michael Dowling 2013-06-03 21:52:05 -07:00
parent 2ef1b4d7ef
commit 21385e1ad2
4 changed files with 52 additions and 6 deletions

View File

@ -194,7 +194,11 @@ class RequestFactory implements RequestFactoryInterface
throw new InvalidArgumentException('auth value must be an array');
}
$request->setAuth($value[0], isset($value[1]) ? $value[1] : null);
$request->setAuth(
$value[0],
isset($value[1]) ? $value[1] : null,
isset($value[2]) ? $value[2] : CURLAUTH_BASIC
);
}
protected function visit_query(RequestInterface $request, $value)
@ -294,4 +298,14 @@ class RequestFactory implements RequestFactoryInterface
}
}
}
protected function visit_save_to(RequestInterface $request, $value)
{
$request->setResponseBody($value);
}
protected function visit_proxy(RequestInterface $request, $value)
{
$request->getCurlOptions()->set(CURLOPT_PROXY, $value);
}
}

View File

@ -68,15 +68,16 @@ 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. Setting
* a body for a GET request will set where the response body is downloaded.
* "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 index 0 is the username and index 1 is the password
* "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

View File

@ -181,14 +181,14 @@ interface RequestInterface extends MessageInterface, HasDispatcherInterface
*
* @param string|bool $user User name or false disable authentication
* @param string $password Password
* @param string $scheme Authentication scheme to use (CURLAUTH_BASIC, CURLAUTH_DIGEST, etc)
* @param int $scheme Authentication scheme to use (CURLAUTH_BASIC, CURLAUTH_DIGEST, etc)
*
* @return self
* @link http://www.ietf.org/rfc/rfc2617.txt
* @link http://php.net/manual/en/function.curl-setopt.php See the available options for CURLOPT_HTTPAUTH
* @throws RequestException
*/
public function setAuth($user, $password = '', $scheme = 'Basic');
public function setAuth($user, $password = '', $scheme = CURLAUTH_BASIC);
/**
* Get the password to pass in the URL if set

View File

@ -391,4 +391,35 @@ class HttpRequestFactoryTest extends \Guzzle\Tests\GuzzleTestCase
));
$request->send();
}
public function testCanDisableExceptions()
{
$client = new Client();
$request = $client->get($this->getServer()->getUrl(), array(), array(
'plugins' => array(new MockPlugin(array(new Response(500)))),
'exceptions' => false
));
$this->assertEquals(500, $request->send()->getStatusCode());
}
public function testCanChangeSaveToLocation()
{
$r = EntityBody::factory();
$client = new Client();
$request = $client->get($this->getServer()->getUrl(), array(), array(
'plugins' => array(new MockPlugin(array(new Response(200, array(), 'testing')))),
'save_to' => $r
));
$request->send();
$this->assertEquals('testing', (string) $r);
}
public function testCanSetProxy()
{
$client = new Client();
$request = $client->get($this->getServer()->getUrl(), array(), array(
'proxy' => '192.168.16.121'
));
$this->assertEquals('192.168.16.121', $request->getCurlOptions()->get(CURLOPT_PROXY));
}
}