Skip to content
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

[Backport release_3_8] fix: In Guzzle, provided HTTP headers is an array #5527

Merged
merged 3 commits into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion lizmap/modules/lizmap/lib/Request/OGCRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.'`.';
}
Expand Down
26 changes: 22 additions & 4 deletions lizmap/modules/lizmap/lib/Request/Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, array<string>> $headers The headers to check
*
* @return string
*/
public static function httpRequestId($headers)
{
$xRequestId = $headers['X-Request-Id'] ?? '';

if (is_string($xRequestId)) {
return '';
}

return implode(',', $xRequestId);
}

/**
* @param string $url
* @param array $options
Expand Down Expand Up @@ -518,17 +536,17 @@ 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<string, string> $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<string, array<string>> $headers The headers of the response
*/
protected static function logRequestIfError($httpCode, $url, $headers = array())
{
if ($httpCode < 400) {
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.'.';
Expand Down
Loading