diff --git a/lizmap/modules/lizmap/lib/Request/OGCRequest.php b/lizmap/modules/lizmap/lib/Request/OGCRequest.php index b279943614..92b7ec7e90 100644 --- a/lizmap/modules/lizmap/lib/Request/OGCRequest.php +++ b/lizmap/modules/lizmap/lib/Request/OGCRequest.php @@ -247,9 +247,14 @@ protected function logRequestIfError($code, $headers) $message = 'The HTTP OGC request to QGIS Server ended with an error.'; - $xRequestId = $headers['X-Request-Id'] ?? ''; - if ($xRequestId !== '') { - $message .= ' The X-Request-Id `'.$xRequestId.'`.'; + if (isset($headers['X-Request-Id'])) { + if (is_array($headers['X-Request-Id'])) { + $xRequestId = implode(',', $headers['X-Request-Id']); + } else { + $xRequestId = $headers['X-Request-Id']; + } + } else { + $xRequestId = ''; } // The master error with MAP parameter diff --git a/lizmap/modules/lizmap/lib/Request/Proxy.php b/lizmap/modules/lizmap/lib/Request/Proxy.php index f855ca55bf..9f1d93c557 100644 --- a/lizmap/modules/lizmap/lib/Request/Proxy.php +++ b/lizmap/modules/lizmap/lib/Request/Proxy.php @@ -310,11 +310,14 @@ protected static function buildHeaders($url, $options) ), $options['headers']); if (strpos($url, self::$services->wmsServerURL) === 0) { - // headers only for QGIS server + // Headers only for QGIS server + parse_str(parse_url($options['headers']['X-Qgis-Service-Url'], PHP_URL_QUERY), $output); + $requestId = $output['repository'].'-'.$output['project']; + $requestId .= '-'.uniqid().'-'.bin2hex(random_bytes(10)); $options['headers'] = array_merge( self::userHttpHeader(), self::$services->wmsServerHeaders, - array('X-Request-Id' => uniqid().'-'.bin2hex(random_bytes(10))), + array('X-Request-Id' => $requestId), $options['headers'] ); } @@ -339,7 +342,16 @@ protected static function logRequestIfError($httpCode, $url, $headers = array()) return; } - $xRequestId = $headers['X-Request-Id'] ?? ''; + if (isset($headers['X-Request-Id'])) { + if (is_array($headers['X-Request-Id'])) { + $xRequestId = implode(',', $headers['X-Request-Id']); + $xRequestId = json_encode($headers['X-Request-Id']); + } else { + $xRequestId = $headers['X-Request-Id']; + } + } else { + $xRequestId = ''; + } $lizmapAdmin = 'An HTTP request ended with an error, please check the main error log.'; $lizmapAdmin .= ' HTTP code '.$httpCode.'.'; diff --git a/tests/units/classes/Request/ProxyTest.php b/tests/units/classes/Request/ProxyTest.php index 765395b731..e5c2c5b654 100644 --- a/tests/units/classes/Request/ProxyTest.php +++ b/tests/units/classes/Request/ProxyTest.php @@ -240,6 +240,7 @@ public function testBuildHeaders($options, $expectedHeaders, $expectedBody, $exp $this->assertEquals($value, $result['headers'][$header]); } $this->assertArrayHasKey('X-Request-Id', $result['headers']); + $this->assertIsString($result['headers']['X-Request-Id']); $this->assertEquals($expectedBody, $result['body']); if ($expectedUrl) { $this->assertEquals($expectedUrl, $url);