Skip to content

Commit

Permalink
Fix HTTP header casing in existsRemote
Browse files Browse the repository at this point in the history
  • Loading branch information
mzur committed Aug 11, 2021
1 parent 77e9335 commit d2fedde
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/FileCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ protected function existsRemote($file)
{
$context = stream_context_create(['http' => ['method'=>'HEAD']]);
$headers = get_headers($file->getUrl(), 1, $context);
$headers = array_change_key_case($headers, CASE_LOWER);

$exists = explode(' ', $headers[0])[1][0] === '2';

Expand All @@ -265,14 +266,14 @@ protected function existsRemote($file)
}

if (!empty($this->config['mime_types'])) {
$type = trim(explode(';', $headers['Content-Type'])[0]);
$type = trim(explode(';', $headers['content-type'])[0]);
if (!in_array($type, $this->config['mime_types'])) {
throw new Exception("MIME type '{$type}' not allowed.");
}
}

$maxBytes = intval($this->config['max_file_size']);
$size = intval($headers['Content-Length']);
$size = intval($headers['content-length']);

if ($maxBytes >= 0 && $size > $maxBytes) {
throw new Exception("The file is too large with more than {$maxBytes} bytes.");
Expand Down

0 comments on commit d2fedde

Please sign in to comment.