Skip to content
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
4 changes: 3 additions & 1 deletion lib/Http/Client/Middleware/HttpClientLoggerMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,9 @@ function ($reason) use ($request, $reqHeaders, $reqId) {
if ($reason instanceof \Throwable) {
throw $reason;
}
throw new \RuntimeException('HTTP request rejected: ' . (string)$reason);
throw new \RuntimeException(
'HTTP request rejected: ' . (is_object($reason) ? get_class($reason) : (string)$reason)
);
}
);
};
Expand Down
7 changes: 6 additions & 1 deletion lib/Http/Client/Middleware/LogWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ public static function write(
LoggerInterface $logger,
): void {
if (in_array($format, ['json', 'both'], true)) {
self::append($jsonFile, json_encode($entry, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . PHP_EOL, $logger);
// Remote servers can send headers with broken UTF-8; substitute
// those bytes instead of losing the whole entry.
$json = json_encode($entry, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_INVALID_UTF8_SUBSTITUTE);
if ($json !== false) {
self::append($jsonFile, $json . PHP_EOL, $logger);
}
}
if (in_array($format, ['plain', 'both'], true)) {
self::append($plainFile, $plainLine, $logger);
Expand Down
Loading