Skip to content

Commit

Permalink
Merge pull request #11 from Thiagoojtds/fix/content-type-validation
Browse files Browse the repository at this point in the history
fix: include insensitive case to get content-type in header filters
  • Loading branch information
jeansouzak authored Aug 22, 2023
2 parents fed02ec + 2eabc5b commit be2306a
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/Filter/WebFileExtensionFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,18 @@ public function __construct($allowedExtensions)
}


public function applyHeaderFilter(array $headers) {
if(!array_key_exists('Content-Type', $headers) && count($headers['Content-Type']) > 0){
public function applyHeaderFilter(array $headers) {
if (!array_key_exists('Content-Type', $headers) && !array_key_exists('content-type', $headers)) {
throw new \Exception('Invalid headers for FileExtension applyHeaderFilter');
}
$headerType = $headers['Content-Type'][0];
if(!ArrayTool::inArrayRecursive(strtolower($headerType), $this->formats)) {
throw new FileExtensionException('Invalid file extension file: '.$headerType);
$contentType = $headers['Content-Type'] ?? $headers['content-type'] ?? null;

if ($contentType == null || count($contentType) == 0) {
throw new \Exception('Missing or empty Content-Type on response header');
}
$fileExtension = $contentType[0];
if (!ArrayTool::inArrayRecursive(strtolower($fileExtension), $this->formats)) {
throw new FileExtensionException('Invalid file extension file: '.$fileExtension);
}
}

Expand Down

0 comments on commit be2306a

Please sign in to comment.