aboutsummaryrefslogtreecommitdiff
path: root/zenserver/frontend/frontend.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2022-06-11 23:22:00 +0200
committerStefan Boberg <[email protected]>2022-06-11 23:22:00 +0200
commit348ae50c946b541ce935703045ab98a49d809ed4 (patch)
treea400285c9e5ae215dc7ef3b2958ce922f48ec7bc /zenserver/frontend/frontend.cpp
parentfixed mac build ("unused" variable) (diff)
parentclang-format fix (diff)
downloadzen-348ae50c946b541ce935703045ab98a49d809ed4.tar.xz
zen-348ae50c946b541ce935703045ab98a49d809ed4.zip
Merge branch 'main' of https://github.com/EpicGames/zen
Diffstat (limited to 'zenserver/frontend/frontend.cpp')
-rw-r--r--zenserver/frontend/frontend.cpp41
1 files changed, 15 insertions, 26 deletions
diff --git a/zenserver/frontend/frontend.cpp b/zenserver/frontend/frontend.cpp
index 6d576876f..842587708 100644
--- a/zenserver/frontend/frontend.cpp
+++ b/zenserver/frontend/frontend.cpp
@@ -203,51 +203,40 @@ HttpFrontendService::HandleRequest(zen::HttpServerRequest& Request)
// Dismiss if the URI contains .. anywhere to prevent arbitrary file reads
if (Uri.find("..") != Uri.npos)
{
- Request.WriteResponse(HttpResponseCode::Forbidden);
- return;
+ return Request.WriteResponse(HttpResponseCode::Forbidden);
}
// Map the file extension to a MIME type. To keep things constrained, only a
- // small subset of file extensions is allowed.
- HttpContentType ContentType = HttpContentType::kCOUNT;
- size_t DotIndex = Uri.rfind(".");
- if (DotIndex != Uri.npos)
+ // small subset of file extensions is allowed
+
+ HttpContentType ContentType = HttpContentType::kUnknownContentType;
+
+ if (const size_t DotIndex = Uri.rfind("."); DotIndex != Uri.npos)
{
- const std::string_view DotExt = Uri.substr(DotIndex);
- if (DotExt == ".html")
- ContentType = HttpContentType::kHTML;
- else if (DotExt == ".js")
- ContentType = HttpContentType::kJSON;
- else if (DotExt == ".css")
- ContentType = HttpContentType::kCSS;
- else if (DotExt == ".png")
- ContentType = HttpContentType::kPNG;
- else if (DotExt == ".ico")
- ContentType = HttpContentType::kIcon;
+ const std::string_view DotExt = Uri.substr(DotIndex + 1);
+
+ ContentType = ParseContentType(DotExt);
}
- if (ContentType == HttpContentType::kCOUNT)
+ if (ContentType == HttpContentType::kUnknownContentType)
{
- Request.WriteResponse(HttpResponseCode::Forbidden);
- return;
+ return Request.WriteResponse(HttpResponseCode::Forbidden);
}
// The given content directory overrides any zip-fs discovered in the binary
if (!m_Directory.empty())
{
FileContents File = ReadFile(m_Directory / Uri);
+
if (!File.ErrorCode)
{
- Request.WriteResponse(HttpResponseCode::OK, ContentType, File.Data[0]);
- return;
+ return Request.WriteResponse(HttpResponseCode::OK, ContentType, File.Data[0]);
}
}
- IoBuffer FileBuffer = m_ZipFs.GetFile(Uri);
- if (FileBuffer)
+ if (IoBuffer FileBuffer = m_ZipFs.GetFile(Uri))
{
- Request.WriteResponse(HttpResponseCode::OK, ContentType, FileBuffer);
- return;
+ return Request.WriteResponse(HttpResponseCode::OK, ContentType, FileBuffer);
}
Request.WriteResponse(HttpResponseCode::NotFound, HttpContentType::kText, "Not found"sv);