From 18ffc206738ab46df90b241ab6a62243715731f1 Mon Sep 17 00:00:00 2001 From: Etienne Trimaille Date: Mon, 27 Jan 2025 16:28:12 +0100 Subject: [PATCH] Guzzle - Content-Type is not always provided --- lizmap/modules/lizmap/lib/Request/Proxy.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lizmap/modules/lizmap/lib/Request/Proxy.php b/lizmap/modules/lizmap/lib/Request/Proxy.php index 7368033b5b..d1da1f7984 100644 --- a/lizmap/modules/lizmap/lib/Request/Proxy.php +++ b/lizmap/modules/lizmap/lib/Request/Proxy.php @@ -465,9 +465,14 @@ public static function getRemoteData($url, $options = null, $debug = null, $meth $options = self::buildOptions($options, $method, $debug); $response = self::sendRequest($url, $options); + $contentType = 'application/octet-stream'; + if ($response->hasHeader('Content-Type')) { + $contentType = $response->getHeader('Content-Type')[0]; + } + return array( (string) $response->getBody(), - $response->getHeader('Content-Type')[0], + $contentType, $response->getStatusCode(), $response->getHeaders(), ); @@ -490,9 +495,14 @@ public static function getRemoteDataAsStream($url, $options = null) $response = self::sendRequest($url, $options); + $contentType = 'application/octet-stream'; + if ($response->hasHeader('Content-Type')) { + $contentType = $response->getHeader('Content-Type')[0]; + } + return new ProxyResponse( $response->getStatusCode(), - $response->getHeader('Content-Type')[0], + $contentType, $response->getHeaders(), $response->getBody() );