Skip to content

Commit 098a7ac

Browse files
lyrixxnicolas-grekas
authored andcommitted
[HttpClient] Adjust logger messages and levels
1 parent 09e8d74 commit 098a7ac

File tree

5 files changed

+18
-13
lines changed

5 files changed

+18
-13
lines changed

src/Symfony/Component/HttpClient/CurlHttpClient.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,18 @@ public function request(string $method, string $url, array $options = []): Respo
110110
];
111111

112112
if ('GET' === $method && !$options['body'] && $expectedHeaders === $pushedHeaders) {
113-
$this->logger && $this->logger->info(sprintf('Connecting request to pushed response: %s %s', $method, $url));
113+
$this->logger && $this->logger->debug(sprintf('Connecting request to pushed response: "%s %s"', $method, $url));
114114

115115
// Reinitialize the pushed response with request's options
116116
$pushedResponse->__construct($this->multi, $url, $options, $this->logger);
117117

118118
return $pushedResponse;
119119
}
120120

121-
$this->logger && $this->logger->info(sprintf('Rejecting pushed response for "%s": authorization headers don\'t match the request', $url));
121+
$this->logger && $this->logger->debug(sprintf('Rejecting pushed response for "%s": authorization headers don\'t match the request', $url));
122122
}
123123

124-
$this->logger && $this->logger->info(sprintf('Request: %s %s', $method, $url));
124+
$this->logger && $this->logger->info(sprintf('Request: "%s %s"', $method, $url));
125125

126126
$curlopts = [
127127
CURLOPT_URL => $url,
@@ -307,15 +307,15 @@ private static function handlePush($parent, $pushed, array $requestHeaders, \std
307307
}
308308

309309
if (!isset($headers[':method']) || !isset($headers[':scheme']) || !isset($headers[':authority']) || !isset($headers[':path']) || 'GET' !== $headers[':method'] || isset($headers['range'])) {
310-
$logger && $logger->info(sprintf('Rejecting pushed response from "%s": pushed headers are invalid', $origin));
310+
$logger && $logger->debug(sprintf('Rejecting pushed response from "%s": pushed headers are invalid', $origin));
311311

312312
return CURL_PUSH_DENY;
313313
}
314314

315315
$url = $headers[':scheme'].'://'.$headers[':authority'];
316316

317317
if ($maxPendingPushes <= \count($multi->pushedResponses)) {
318-
$logger && $logger->info(sprintf('Rejecting pushed response from "%s" for "%s": the queue is full', $origin, $url));
318+
$logger && $logger->debug(sprintf('Rejecting pushed response from "%s" for "%s": the queue is full', $origin, $url));
319319

320320
return CURL_PUSH_DENY;
321321
}
@@ -324,13 +324,13 @@ private static function handlePush($parent, $pushed, array $requestHeaders, \std
324324
// but this is a MUST in the HTTP/2 RFC; let's restrict pushes to the original host,
325325
// ignoring domains mentioned as alt-name in the certificate for now (same as curl).
326326
if (0 !== strpos($origin, $url.'/')) {
327-
$logger && $logger->info(sprintf('Rejecting pushed response from "%s": server is not authoritative for "%s"', $origin, $url));
327+
$logger && $logger->debug(sprintf('Rejecting pushed response from "%s": server is not authoritative for "%s"', $origin, $url));
328328

329329
return CURL_PUSH_DENY;
330330
}
331331

332332
$url .= $headers[':path'];
333-
$logger && $logger->info(sprintf('Queueing pushed response: %s', $url));
333+
$logger && $logger->debug(sprintf('Queueing pushed response: "%s"', $url));
334334

335335
$multi->pushedResponses[$url] = [
336336
new CurlResponse($multi, $pushed),

src/Symfony/Component/HttpClient/HttpClientTrait.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,13 @@ trait HttpClientTrait
3434
*/
3535
private static function prepareRequest(?string $method, ?string $url, array $options, array $defaultOptions = [], bool $allowExtraOptions = false): array
3636
{
37-
if (null !== $method && \strlen($method) !== strspn($method, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')) {
38-
throw new InvalidArgumentException(sprintf('Invalid HTTP method "%s", only uppercase letters are accepted.', $method));
37+
if (null !== $method) {
38+
if (\strlen($method) !== strspn($method, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')) {
39+
throw new InvalidArgumentException(sprintf('Invalid HTTP method "%s", only uppercase letters are accepted.', $method));
40+
}
41+
if (!$method) {
42+
throw new InvalidArgumentException('The HTTP method can not be empty.');
43+
}
3944
}
4045

4146
$options = self::mergeDefaultOptions($options, $defaultOptions, $allowExtraOptions);

src/Symfony/Component/HttpClient/Response/CurlResponse.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public function __destruct()
180180
if (!$this->multi->openHandles) {
181181
if ($this->logger) {
182182
foreach ($this->multi->pushedResponses as $url => $response) {
183-
$this->logger->info(sprintf('Unused pushed response: %s', $url));
183+
$this->logger->debug(sprintf('Unused pushed response: "%s"', $url));
184184
}
185185
}
186186

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

320320
curl_setopt($ch, CURLOPT_PRIVATE, 'content');
321321
} elseif (null !== $info['redirect_url'] && $logger) {
322-
$logger->info(sprintf('Redirecting: %s %s', $info['http_code'], $info['redirect_url']));
322+
$logger->info(sprintf('Redirecting: "%s %s"', $info['http_code'], $info['redirect_url']));
323323
}
324324

325325
return \strlen($data);

src/Symfony/Component/HttpClient/Response/NativeResponse.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ private function open(): void
120120
break;
121121
}
122122

123-
$this->logger && $this->logger->info(sprintf('Redirecting: %s %s', $this->info['http_code'], $url ?? $this->url));
123+
$this->logger && $this->logger->info(sprintf('Redirecting: "%s %s"', $this->info['http_code'], $url ?? $this->url));
124124
}
125125
} catch (\Throwable $e) {
126126
$this->close();

src/Symfony/Component/HttpClient/Response/ResponseTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ public static function stream(iterable $responses, float $timeout = null): \Gene
302302
$isTimeout = true;
303303
} elseif ($chunk instanceof FirstChunk && $response->logger) {
304304
$info = $response->getInfo();
305-
$response->logger->info(sprintf('Response: %s %s', $info['http_code'], $info['url']));
305+
$response->logger->info(sprintf('Response: "%s %s"', $info['http_code'], $info['url']));
306306
}
307307

308308
yield $response => $chunk;

0 commit comments

Comments
 (0)