NotFound middleware returns prettier error

This commit is contained in:
2019-06-15 21:15:30 +02:00
parent 9e99dc104f
commit 132f17e0d5

View File

@@ -1,3 +1,4 @@
#include "../http/mime.hpp"
#include "notfound.hpp" #include "notfound.hpp"
#include <sstream> #include <sstream>
@@ -11,17 +12,17 @@ namespace Middleware
} }
response.code = HttpResponse::Code::NOT_FOUND; response.code = HttpResponse::Code::NOT_FOUND;
response.contentType = Http::GetMimeType(Http::FileType::HTML);
std::stringstream ss; std::stringstream ss;
ss << "404 - file not found\n"; ss << "<!DOCTYPE html><html><head></head><body>";
ss << "File: "; ss << "<h1>404 - File Not Found</h1>";
ss << request.url.GetPath() << '\n'; ss << "<p>File: " << request.url.GetPath() << "<p>";
ss << "</body></html>";
auto responseContent = ss.str(); auto responseContent = ss.str();
response.content.insert(response.content.begin(), response.content.insert(response.content.begin(),
responseContent.begin(), responseContent.begin(),
responseContent.end()); responseContent.end());
response.contentType = "text/plain";
} }
} }