Skip to content

Commit

Permalink
Add error handling in mime type detection
Browse files Browse the repository at this point in the history
  • Loading branch information
endroid committed Sep 8, 2024
1 parent 5f6a488 commit 393fec6
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/ImageData/LogoImageData.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,14 @@ public function createDataUri(): string
private static function detectMimeTypeFromUrl(string $url): string
{
$headers = get_headers($url, true);

if (!is_array($headers)) {
throw new \Exception(sprintf('Could not retrieve headers to determine content type for logo URL "%s"', $url));
}

$headers = array_combine(array_map('strtolower', array_keys($headers)), $headers);

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

Expand Down

0 comments on commit 393fec6

Please sign in to comment.