Skip to content

[HttpClient] Adjust logger messages and levels #30873

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/Symfony/Component/HttpClient/CurlHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,18 @@ public function request(string $method, string $url, array $options = []): Respo
];

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);

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,
Expand Down Expand Up @@ -307,15 +307,15 @@ private static function handlePush($parent, $pushed, array $requestHeaders, \std
}

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;
}

$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;
}
Expand All @@ -324,13 +324,13 @@ private static function handlePush($parent, $pushed, array $requestHeaders, \std
// 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),
Expand Down
9 changes: 7 additions & 2 deletions src/Symfony/Component/HttpClient/HttpClientTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/HttpClient/Response/CurlResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public function __destruct()
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));
}
}

Expand Down Expand Up @@ -319,7 +319,7 @@ private static function parseHeaderLine($ch, string $data, array &$info, array &

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private function open(): void
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public static function stream(iterable $responses, float $timeout = null): \Gene
$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;
Expand Down