Bin some duplicate 404 handling

Change-Id: Ibf3ed6c5558492b122662f25f31d321a6bbc151c
This commit is contained in:
Pranav Kant 2017-11-10 12:35:34 +05:30
parent 377faf3971
commit 768b0c0404

View file

@ -164,10 +164,10 @@ void FileServerRequestHandler::handleRequest(const HTTPRequest& request, Poco::M
std::vector<std::string> requestSegments;
requestUri.getPathSegments(requestSegments);
if (requestSegments.size() < 1)
{
const std::string relPath = getRequestPathname(request);
// Is this a file we read at startup - if not; its not for serving.
if (requestSegments.size() < 1 || FileHash.find(relPath) == FileHash.end())
throw Poco::FileNotFoundException("Invalid URI request: [" + requestUri.toString() + "].");
}
const auto& config = Application::instance().config();
const std::string loleafletHtml = config.getString("loleaflet_html", "loleaflet.html");
@ -195,11 +195,6 @@ void FileServerRequestHandler::handleRequest(const HTTPRequest& request, Poco::M
response.add("Referrer-Policy", "no-referrer");
}
const std::string relPath = getRequestPathname(request);
// Is this a file we read at startup - if not; its not for serving.
if (FileHash.find(relPath) == FileHash.end())
throw Poco::FileAccessDeniedException("Invalid or forbidden file path: [" + relPath + "].");
// Do we have an extension.
const std::size_t extPoint = endPoint.find_last_of('.');
if (extPoint == std::string::npos)
@ -441,21 +436,6 @@ void FileServerRequestHandler::preprocessFile(const HTTPRequest& request, Poco::
// Is this a file we read at startup - if not; its not for serving.
const std::string relPath = getRequestPathname(request);
LOG_DBG("Preprocessing file: " << relPath);
if (FileHash.find(relPath) == FileHash.end())
{
LOG_ERR("File [" << relPath << "] does not exist.");
// 404 not found
std::ostringstream oss;
oss << "HTTP/1.1 404\r\n"
<< "Date: " << Poco::DateTimeFormatter::format(Poco::Timestamp(), Poco::DateTimeFormat::HTTP_FORMAT) << "\r\n"
<< "User-Agent: " << WOPI_AGENT_STRING << "\r\n"
<< "Content-Length: 0\r\n"
<< "\r\n";
socket->send(oss.str());
return;
}
std::string preprocess = *getUncompressedFile(relPath);
HTMLForm form(request, message);