diff --git a/lizmap/modules/lizmap/lib/Request/OGCRequest.php b/lizmap/modules/lizmap/lib/Request/OGCRequest.php index ca72fbb813..5e9ec84096 100644 --- a/lizmap/modules/lizmap/lib/Request/OGCRequest.php +++ b/lizmap/modules/lizmap/lib/Request/OGCRequest.php @@ -244,7 +244,7 @@ protected function logRequestIfError($code, $headers) $message = 'The HTTP OGC request to QGIS Server ended with an error.'; - $xRequestId = $headers['X-Request-Id'] ?? ''; + $xRequestId = Proxy::httpRequestId($headers); if ($xRequestId !== '') { $message .= ' The X-Request-Id `'.$xRequestId.'`.'; } diff --git a/lizmap/modules/lizmap/lib/Request/Proxy.php b/lizmap/modules/lizmap/lib/Request/Proxy.php index 24010e6972..2e0a4b324d 100644 --- a/lizmap/modules/lizmap/lib/Request/Proxy.php +++ b/lizmap/modules/lizmap/lib/Request/Proxy.php @@ -275,6 +275,24 @@ protected static function buildOptions($options, $method, $debug) return $options; } + /** + * Get the X-Request-Id of the request from the given headers. + * + * @param array> $headers The headers to check. Note, it can be array if headers are not from Guzzle + * + * @return string + */ + public static function httpRequestId($headers) + { + $xRequestId = $headers['X-Request-Id'] ?? ''; + + if (is_string($xRequestId)) { + return $xRequestId; + } + + return implode(',', $xRequestId); + } + /** * @param string $url * @param array $options @@ -518,9 +536,9 @@ protected static function fileProxy($url, $options) /** * Log if the HTTP code is a 4XX or 5XX error code. * - * @param int $httpCode The HTTP code of the request - * @param string $url The URL of the request, for logging - * @param array $headers The headers of the response + * @param int $httpCode The HTTP code of the request + * @param string $url The URL of the request, for logging + * @param array> $headers The headers of the response */ protected static function logRequestIfError($httpCode, $url, $headers = array()) { @@ -528,7 +546,7 @@ protected static function logRequestIfError($httpCode, $url, $headers = array()) return; } - $xRequestId = $headers['X-Request-Id'] ?? ''; + $xRequestId = self::httpRequestId($headers); $lizmapAdmin = 'An HTTP request ended with an error, please check the main error log.'; $lizmapAdmin .= ' HTTP code '.$httpCode.'.';