Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: include insensitive case to get content-type in header filters #11

Merged
merged 4 commits into from
Aug 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Thiagoojtds marked this conversation as resolved.
Show resolved Hide resolved

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