I'm having some problems to send consecutive request with digest auth.
Only the first one is working as expected, the second one throw Request Exception with status code 401 (Unauthorized) , that means guzzle is losing credentials after first request.
Follow de Code:
class Alice
{
/**
* @var GuzzleHttpClient
*/
private $httpClient;
public function __construct(GuzzleHttpClient $client)
{
$this->httpClient = $client;
}
public function getAll(array $data)
{
$return = array();
foreach ($data as $uri) {
$return[] = $this->callEndpoint($uri);
}
return $return;
}
private function callEndpoint($uri)
{
$httpClient = $this->httpClient;
$response = $httpClient->get(
'http://foo.net/bar/' . $uri,
$this->requestOptions()
);
return $response->json();
}
private function requestOptions()
{
return array(
'auth' => array(
'user',
'password',
'digest'
),
'headers' => array(
'Accept'=>'application/vnd.foo+json; version=1.0',
),
);
}
}
I Resolve it creating new instance of httpClient
$httpClient = new $this->httpClient;
But i don't thing this is the best solution.
Can i resolve it without creating a new instance?