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

Rewrite of MimeTypeMap to support extensions with multiple mimetypes #296

Merged
merged 4 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 6 additions & 6 deletions src/Altinn.App.Api/Controllers/ResourceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public IActionResult Index(string org, string app, string id)

if (fileContent != null)
{
return new FileContentResult(fileContent, MimeTypeMap.GetMimeType(Path.GetExtension(id).ToLower()));
return new FileContentResult(fileContent, MimeTypeMap.GetMimeType(Path.GetExtension(id).ToLower()).ToString());
}

if (id == _appSettings.RuleConfigurationJSONFileName || id == _appSettings.RuleHandlerFileName)
Expand All @@ -75,7 +75,7 @@ public IActionResult GetRuntimeResource(string id)

if (fileContent != null)
{
return new FileContentResult(fileContent, MimeTypeMap.GetMimeType(Path.GetExtension(id).ToLower()));
return new FileContentResult(fileContent, MimeTypeMap.GetMimeType(Path.GetExtension(id).ToLower()).ToString());
}

return StatusCode(404);
Expand All @@ -99,14 +99,14 @@ public IActionResult GetTextResources(string org, string app)
byte[] fileContent = _appResourceService.GetText(org, app, id);
if (fileContent != null)
{
return new FileContentResult(fileContent, MimeTypeMap.GetMimeType(Path.GetExtension(id).ToLower()));
return new FileContentResult(fileContent, MimeTypeMap.GetMimeType(Path.GetExtension(id).ToLower()).ToString());
}

id = $"resource.{defaultLang}.json";
fileContent = _appResourceService.GetText(org, app, id);
if (fileContent != null)
{
return new FileContentResult(fileContent, MimeTypeMap.GetMimeType(Path.GetExtension(id).ToLower()));
return new FileContentResult(fileContent, MimeTypeMap.GetMimeType(Path.GetExtension(id).ToLower()).ToString());
}

return StatusCode(404);
Expand Down Expand Up @@ -226,7 +226,7 @@ public ActionResult GetRulehandler(string org, string app, string id)
byte[] fileContent = _appResourceService.GetRuleHandlerForSet(id);
if (fileContent != null)
{
return new FileContentResult(fileContent, MimeTypeMap.GetMimeType(".ts"));
return new FileContentResult(fileContent, MimeTypeMap.GetMimeType(".ts").ToString());
}

return NoContent();
Expand All @@ -249,7 +249,7 @@ public ActionResult GetRuleConfiguration(string org, string app, string id)
return NoContent();
}

return new FileContentResult(fileContent, MimeTypeMap.GetMimeType(".json"));
return new FileContentResult(fileContent, MimeTypeMap.GetMimeType(".json").ToString());
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static (bool Success, List<ValidationIssue> Errors) CompliesWithDataRestr
}

string filetype = splitFilename[splitFilename.Length - 1];
string mimeType = MimeTypeMap.GetMimeType(filetype);
var mimeType = MimeTypeMap.GetMimeType(filetype);

if (!request.Headers.TryGetValue("Content-Type", out StringValues contentType))
{
Expand All @@ -97,7 +97,7 @@ public static (bool Success, List<ValidationIssue> Errors) CompliesWithDataRestr
}

// Verify that file mime type matches content type in request
if (!contentType.Equals("application/octet-stream") && !mimeType.Equals(contentType, StringComparison.InvariantCultureIgnoreCase))
if (!contentType.Equals("application/octet-stream") && !mimeType.Equals(contentType))
{
errors.Add(new ValidationIssue
{
Expand All @@ -110,7 +110,7 @@ public static (bool Success, List<ValidationIssue> Errors) CompliesWithDataRestr
}

// Verify that file mime type is an allowed content-type
if (!dataType.AllowedContentTypes.Contains(mimeType, StringComparer.InvariantCultureIgnoreCase) && !dataType.AllowedContentTypes.Contains("application/octet-stream"))
if (!dataType.AllowedContentTypes.Contains(contentType.ToString(), StringComparer.InvariantCultureIgnoreCase) && !dataType.AllowedContentTypes.Contains("application/octet-stream"))
{
errors.Add(new ValidationIssue
{
Expand Down
Loading