Skip to content

Commit 3f12763

Browse files
authored
Merge pull request #5525 from Gustry/request-id-guzzle
fix: In Guzzle, provided HTTP headers is an array
2 parents dae2f77 + e3cd013 commit 3f12763

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

lizmap/modules/lizmap/lib/Request/OGCRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ protected function logRequestIfError($code, $headers)
247247

248248
$message = 'The HTTP OGC request to QGIS Server ended with an error.';
249249

250-
$xRequestId = $headers['X-Request-Id'] ?? '';
250+
$xRequestId = Proxy::httpRequestId($headers);
251251
if ($xRequestId !== '') {
252252
$message .= ' The X-Request-Id `'.$xRequestId.'`.';
253253
}

lizmap/modules/lizmap/lib/Request/Proxy.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,24 @@ protected static function buildOptions($options, $method, $debug)
282282
return $options;
283283
}
284284

285+
/**
286+
* Get the X-Request-Id of the request from the given headers.
287+
*
288+
* @param array<string, array<string>> $headers The headers to check
289+
*
290+
* @return string
291+
*/
292+
public static function httpRequestId($headers)
293+
{
294+
$xRequestId = $headers['X-Request-Id'] ?? '';
295+
296+
if (is_string($xRequestId)) {
297+
return '';
298+
}
299+
300+
return implode(',', $xRequestId);
301+
}
302+
285303
/**
286304
* @param string $url
287305
* @param array $options
@@ -329,17 +347,17 @@ protected static function buildHeaders($url, $options)
329347
/**
330348
* Log if the HTTP code is a 4XX or 5XX error code.
331349
*
332-
* @param int $httpCode The HTTP code of the request
333-
* @param string $url The URL of the request, for logging
334-
* @param array<string, string> $headers The headers of the response
350+
* @param int $httpCode The HTTP code of the request
351+
* @param string $url The URL of the request, for logging
352+
* @param array<string, array<string>> $headers The headers of the response
335353
*/
336354
protected static function logRequestIfError($httpCode, $url, $headers = array())
337355
{
338356
if ($httpCode < 400) {
339357
return;
340358
}
341359

342-
$xRequestId = $headers['X-Request-Id'] ?? '';
360+
$xRequestId = self::httpRequestId($headers);
343361

344362
$lizmapAdmin = 'An HTTP request ended with an error, please check the main error log.';
345363
$lizmapAdmin .= ' HTTP code '.$httpCode.'.';

0 commit comments

Comments
 (0)