[Libreoffice-commits] online.git: wsd/FileServer.cpp

Pranav Kant pranavk at collabora.co.uk
Fri Nov 10 07:07:20 UTC 2017


 wsd/FileServer.cpp |   26 +++-----------------------
 1 file changed, 3 insertions(+), 23 deletions(-)

New commits:
commit 768b0c040493ef983fba683a677ca3baad3b792f
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Fri Nov 10 12:35:34 2017 +0530

    Bin some duplicate 404 handling
    
    Change-Id: Ibf3ed6c5558492b122662f25f31d321a6bbc151c

diff --git a/wsd/FileServer.cpp b/wsd/FileServer.cpp
index 2fa659c2..a0e74a2c 100644
--- a/wsd/FileServer.cpp
+++ b/wsd/FileServer.cpp
@@ -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);


More information about the Libreoffice-commits mailing list