Initial commit
This commit is contained in:
27
src/middleware/notfound.cpp
Normal file
27
src/middleware/notfound.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#include "notfound.hpp"
|
||||
#include <sstream>
|
||||
|
||||
namespace Middleware
|
||||
{
|
||||
void NotFound::HandleRequest(Http::Request const & request, Http::Response & response)
|
||||
{
|
||||
if (response.code != HttpResponse::Code::UNKNOWN)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
response.code = HttpResponse::Code::NOT_FOUND;
|
||||
|
||||
std::stringstream ss;
|
||||
ss << "404 - file not found\n";
|
||||
ss << "File: ";
|
||||
ss << request.path << '\n';
|
||||
|
||||
auto responseContent = ss.str();
|
||||
response.content.insert(response.content.begin(),
|
||||
responseContent.begin(),
|
||||
responseContent.end());
|
||||
|
||||
response.contentType = "text/plain";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user