Skip to content

Commit

Permalink
Bugfix: Lower-case HTTP header parameters (#454)
Browse files Browse the repository at this point in the history
If a web server (such as LiteSpeed) sends lowercase header parameter names, this triggers an exception. By changing all parameter names to lower case, we avoid this problem.
  • Loading branch information
PaulGossen authored Sep 8, 2024
1 parent de42ba7 commit 5f6a488
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/ImageData/LogoImageData.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,13 @@ public function createDataUri(): string
private static function detectMimeTypeFromUrl(string $url): string
{
$headers = get_headers($url, true);
$headers = array_combine(array_map('strtolower', array_keys($headers)), $headers);

Check failure on line 116 in src/ImageData/LogoImageData.php

View workflow job for this annotation

GitHub Actions / build (8.1)

Parameter #1 $array of function array_keys expects array, array|false given.

Check failure on line 116 in src/ImageData/LogoImageData.php

View workflow job for this annotation

GitHub Actions / build (8.1)

Parameter #2 $values of function array_combine expects array, array|false given.

Check failure on line 116 in src/ImageData/LogoImageData.php

View workflow job for this annotation

GitHub Actions / build (8.2)

Parameter #1 $array of function array_keys expects array, array|false given.

Check failure on line 116 in src/ImageData/LogoImageData.php

View workflow job for this annotation

GitHub Actions / build (8.2)

Parameter #2 $values of function array_combine expects array, array|false given.

Check failure on line 116 in src/ImageData/LogoImageData.php

View workflow job for this annotation

GitHub Actions / build (8.3)

Parameter #1 $array of function array_keys expects array, array|false given.

Check failure on line 116 in src/ImageData/LogoImageData.php

View workflow job for this annotation

GitHub Actions / build (8.3)

Parameter #2 $values of function array_combine expects array, array|false given.

if (!is_array($headers) || !isset($headers['Content-Type'])) {
if (!is_array($headers) || !isset($headers['content-type'])) {
throw new \Exception(sprintf('Content type could not be determined for logo URL "%s"', $url));
}

return is_array($headers['Content-Type']) ? $headers['Content-Type'][1] : $headers['Content-Type'];
return is_array($headers['content-type']) ? $headers['content-type'][1] : $headers['content-type'];
}

private static function detectMimeTypeFromPath(string $path): string
Expand Down

0 comments on commit 5f6a488

Please sign in to comment.