[HttpClient] Adjust logger messages and levels

This commit is contained in:
Grégoire Pineau 2019-04-05 15:04:18 +02:00 committed by Nicolas Grekas
parent 09e8d74627
commit 098a7ac1af
5 changed files with 18 additions and 13 deletions

View File

@ -110,7 +110,7 @@ final class CurlHttpClient implements HttpClientInterface, LoggerAwareInterface
];
if ('GET' === $method && !$options['body'] && $expectedHeaders === $pushedHeaders) {
$this->logger && $this->logger->info(sprintf('Connecting request to pushed response: %s %s', $method, $url));
$this->logger && $this->logger->debug(sprintf('Connecting request to pushed response: "%s %s"', $method, $url));
// Reinitialize the pushed response with request's options
$pushedResponse->__construct($this->multi, $url, $options, $this->logger);
@ -118,10 +118,10 @@ final class CurlHttpClient implements HttpClientInterface, LoggerAwareInterface
return $pushedResponse;
}
$this->logger && $this->logger->info(sprintf('Rejecting pushed response for "%s": authorization headers don\'t match the request', $url));
$this->logger && $this->logger->debug(sprintf('Rejecting pushed response for "%s": authorization headers don\'t match the request', $url));
}
$this->logger && $this->logger->info(sprintf('Request: %s %s', $method, $url));
$this->logger && $this->logger->info(sprintf('Request: "%s %s"', $method, $url));
$curlopts = [
CURLOPT_URL => $url,
@ -307,7 +307,7 @@ final class CurlHttpClient implements HttpClientInterface, LoggerAwareInterface
}
if (!isset($headers[':method']) || !isset($headers[':scheme']) || !isset($headers[':authority']) || !isset($headers[':path']) || 'GET' !== $headers[':method'] || isset($headers['range'])) {
$logger && $logger->info(sprintf('Rejecting pushed response from "%s": pushed headers are invalid', $origin));
$logger && $logger->debug(sprintf('Rejecting pushed response from "%s": pushed headers are invalid', $origin));
return CURL_PUSH_DENY;
}
@ -315,7 +315,7 @@ final class CurlHttpClient implements HttpClientInterface, LoggerAwareInterface
$url = $headers[':scheme'].'://'.$headers[':authority'];
if ($maxPendingPushes <= \count($multi->pushedResponses)) {
$logger && $logger->info(sprintf('Rejecting pushed response from "%s" for "%s": the queue is full', $origin, $url));
$logger && $logger->debug(sprintf('Rejecting pushed response from "%s" for "%s": the queue is full', $origin, $url));
return CURL_PUSH_DENY;
}
@ -324,13 +324,13 @@ final class CurlHttpClient implements HttpClientInterface, LoggerAwareInterface
// but this is a MUST in the HTTP/2 RFC; let's restrict pushes to the original host,
// ignoring domains mentioned as alt-name in the certificate for now (same as curl).
if (0 !== strpos($origin, $url.'/')) {
$logger && $logger->info(sprintf('Rejecting pushed response from "%s": server is not authoritative for "%s"', $origin, $url));
$logger && $logger->debug(sprintf('Rejecting pushed response from "%s": server is not authoritative for "%s"', $origin, $url));
return CURL_PUSH_DENY;
}
$url .= $headers[':path'];
$logger && $logger->info(sprintf('Queueing pushed response: %s', $url));
$logger && $logger->debug(sprintf('Queueing pushed response: "%s"', $url));
$multi->pushedResponses[$url] = [
new CurlResponse($multi, $pushed),

View File

@ -34,8 +34,13 @@ trait HttpClientTrait
*/
private static function prepareRequest(?string $method, ?string $url, array $options, array $defaultOptions = [], bool $allowExtraOptions = false): array
{
if (null !== $method && \strlen($method) !== strspn($method, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')) {
throw new InvalidArgumentException(sprintf('Invalid HTTP method "%s", only uppercase letters are accepted.', $method));
if (null !== $method) {
if (\strlen($method) !== strspn($method, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')) {
throw new InvalidArgumentException(sprintf('Invalid HTTP method "%s", only uppercase letters are accepted.', $method));
}
if (!$method) {
throw new InvalidArgumentException('The HTTP method can not be empty.');
}
}
$options = self::mergeDefaultOptions($options, $defaultOptions, $allowExtraOptions);

View File

@ -180,7 +180,7 @@ final class CurlResponse implements ResponseInterface
if (!$this->multi->openHandles) {
if ($this->logger) {
foreach ($this->multi->pushedResponses as $url => $response) {
$this->logger->info(sprintf('Unused pushed response: %s', $url));
$this->logger->debug(sprintf('Unused pushed response: "%s"', $url));
}
}
@ -319,7 +319,7 @@ final class CurlResponse implements ResponseInterface
curl_setopt($ch, CURLOPT_PRIVATE, 'content');
} elseif (null !== $info['redirect_url'] && $logger) {
$logger->info(sprintf('Redirecting: %s %s', $info['http_code'], $info['redirect_url']));
$logger->info(sprintf('Redirecting: "%s %s"', $info['http_code'], $info['redirect_url']));
}
return \strlen($data);

View File

@ -120,7 +120,7 @@ final class NativeResponse implements ResponseInterface
break;
}
$this->logger && $this->logger->info(sprintf('Redirecting: %s %s', $this->info['http_code'], $url ?? $this->url));
$this->logger && $this->logger->info(sprintf('Redirecting: "%s %s"', $this->info['http_code'], $url ?? $this->url));
}
} catch (\Throwable $e) {
$this->close();

View File

@ -302,7 +302,7 @@ trait ResponseTrait
$isTimeout = true;
} elseif ($chunk instanceof FirstChunk && $response->logger) {
$info = $response->getInfo();
$response->logger->info(sprintf('Response: %s %s', $info['http_code'], $info['url']));
$response->logger->info(sprintf('Response: "%s %s"', $info['http_code'], $info['url']));
}
yield $response => $chunk;