Use url parsing

This commit is contained in:
2019-06-15 20:52:40 +02:00
parent 22d5430e57
commit 71a7aa147c
10 changed files with 126 additions and 71 deletions

View File

@@ -5,7 +5,7 @@ namespace Middleware
{
void NotFound::HandleRequest(Http::Request const & request, Http::Response & response)
{
if (response.code != HttpResponse::Code::UNKNOWN)
if (response.code != HttpResponse::Code::UNKNOWN || request.requestType != HttpRequest::Type::GET)
{
return;
}
@@ -15,7 +15,7 @@ namespace Middleware
std::stringstream ss;
ss << "404 - file not found\n";
ss << "File: ";
ss << request.path << '\n';
ss << request.url.GetPath() << '\n';
auto responseContent = ss.str();
response.content.insert(response.content.begin(),

View File

@@ -34,24 +34,18 @@ namespace Middleware
}
std::filesystem::path path;
if (request.path.size() == 1)
if (request.url.HasPath())
{
path = root + request.url.GetPath();
}
else
{
// TODO make configurable?
path = root + "/index.html";
}
else
{
path = root + request.path;
}
if (!std::filesystem::exists(path))
{
std::stringstream ss;
ss << "Static file <";
ss << path.string();
ss << "> not found";
Logger::GetInstance().Info(ss.str());
return;
}