Use url parsing
This commit is contained in:
@@ -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(),
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user