From 098a7ac1af42e068d4cc5dd647ff82c24502c6c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Fri, 5 Apr 2019 15:04:18 +0200 Subject: [PATCH] [HttpClient] Adjust logger messages and levels --- .../Component/HttpClient/CurlHttpClient.php | 14 +++++++------- .../Component/HttpClient/HttpClientTrait.php | 9 +++++++-- .../Component/HttpClient/Response/CurlResponse.php | 4 ++-- .../HttpClient/Response/NativeResponse.php | 2 +- .../HttpClient/Response/ResponseTrait.php | 2 +- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/Symfony/Component/HttpClient/CurlHttpClient.php b/src/Symfony/Component/HttpClient/CurlHttpClient.php index f7cb71577f2a7..a6761e23e8a27 100644 --- a/src/Symfony/Component/HttpClient/CurlHttpClient.php +++ b/src/Symfony/Component/HttpClient/CurlHttpClient.php @@ -110,7 +110,7 @@ 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); @@ -118,10 +118,10 @@ public function request(string $method, string $url, array $options = []): Respo 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 @@ 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; } @@ -315,7 +315,7 @@ private static function handlePush($parent, $pushed, array $requestHeaders, \std $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 @@ 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), diff --git a/src/Symfony/Component/HttpClient/HttpClientTrait.php b/src/Symfony/Component/HttpClient/HttpClientTrait.php index 5fc2ca65f53c9..678d9d05b48a5 100644 --- a/src/Symfony/Component/HttpClient/HttpClientTrait.php +++ b/src/Symfony/Component/HttpClient/HttpClientTrait.php @@ -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); diff --git a/src/Symfony/Component/HttpClient/Response/CurlResponse.php b/src/Symfony/Component/HttpClient/Response/CurlResponse.php index 39e256785d341..b98a2cb8ff15e 100644 --- a/src/Symfony/Component/HttpClient/Response/CurlResponse.php +++ b/src/Symfony/Component/HttpClient/Response/CurlResponse.php @@ -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)); } } @@ -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); diff --git a/src/Symfony/Component/HttpClient/Response/NativeResponse.php b/src/Symfony/Component/HttpClient/Response/NativeResponse.php index 6c3330a1638e4..b6652f75a05f7 100644 --- a/src/Symfony/Component/HttpClient/Response/NativeResponse.php +++ b/src/Symfony/Component/HttpClient/Response/NativeResponse.php @@ -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(); diff --git a/src/Symfony/Component/HttpClient/Response/ResponseTrait.php b/src/Symfony/Component/HttpClient/Response/ResponseTrait.php index 734359f08d375..fc557ea90fcf2 100644 --- a/src/Symfony/Component/HttpClient/Response/ResponseTrait.php +++ b/src/Symfony/Component/HttpClient/Response/ResponseTrait.php @@ -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; pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy