Files
http-server/src/middleware/notfound.cpp

27 lines
635 B
C++

#include "notfound.hpp"
#include <sstream>
namespace Middleware
{
void NotFound::HandleRequest(Http::Request const & request, Http::Response & response)
{
if (response.code != HttpResponse::Code::UNKNOWN || request.requestType != HttpRequest::Type::GET)
{
return;
}
response.code = HttpResponse::Code::NOT_FOUND;
std::stringstream ss;
ss << "404 - file not found\n";
ss << "File: ";
ss << request.url.GetPath() << '\n';
auto responseContent = ss.str();
response.content.insert(response.content.begin(),
responseContent.begin(),
responseContent.end());
response.contentType = "text/plain";
}
}