private function doPollForChallenge($location)
{
if (!is_string($location)) {
throw new InvalidArgumentException(sprintf("\$location must be of type string, %s given.", gettype($location)));
}
do {
/** @var Response $response */
$response = (yield $this->acmeClient->get($location));
$data = json_decode($response->getBody());
if ($data->status === "pending") {
if (!$response->hasHeader("retry-after")) {
// throw new AcmeException("Protocol Violation: No Retry-After Header!");
(yield new Pause(1000));
continue;
}
$waitTime = $this->parseRetryAfter(current($response->getHeader("retry-after")));
$waitTime = max($waitTime, 1);
(yield new Pause($waitTime * 1000));
continue;
} elseif ($data->status === "invalid") {
throw new AcmeException("Challenge marked as invalid!");
} elseif ($data->status === "valid") {
break;
} else {
throw new AcmeException("Invalid challenge status: {$data->status}.");
}
} while (1);
}