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

Andras Timar andras.timar at collabora.com
Fri May 18 12:17:42 UTC 2018


 net/Socket.cpp     |    4 ++++
 wsd/FileServer.cpp |   21 ++++++++++++++++++---
 2 files changed, 22 insertions(+), 3 deletions(-)

New commits:
commit d66e8d13b7fc0fc638122fae44cf1591eca1aaca
Author: Andras Timar <andras.timar at collabora.com>
Date:   Fri May 18 09:48:07 2018 +0200

    serve files with old gith hash in their path, that comes from cached discovery.xml
    
    moreover:
    * noCache is always true in debug mode
    * when noCache is true we return an explicit "Cache-Control: no-cache" line
    
    Change-Id: I157a410df0a90f9ab151b899e44566b95cbd9929
    Reviewed-on: https://gerrit.libreoffice.org/54517
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
    Tested-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/net/Socket.cpp b/net/Socket.cpp
index 9a07986c9..4faa4f753 100644
--- a/net/Socket.cpp
+++ b/net/Socket.cpp
@@ -374,6 +374,10 @@ namespace HttpHelper
             response.set("Cache-Control", "max-age=11059200");
             response.set("ETag", "\"" LOOLWSD_VERSION_HASH "\"");
         }
+        else
+        {
+            response.set("Cache-Control", "no-cache");
+        }
 
         response.setContentType(mediaType);
         response.add("X-Content-Type-Options", "nosniff");
diff --git a/wsd/FileServer.cpp b/wsd/FileServer.cpp
index f8e62f4a5..ab95c6a45 100644
--- a/wsd/FileServer.cpp
+++ b/wsd/FileServer.cpp
@@ -33,6 +33,7 @@
 #include <Poco/Net/HTTPResponse.h>
 #include <Poco/Net/NameValueCollection.h>
 #include <Poco/Net/NetException.h>
+#include <Poco/RegularExpression.h>
 #include <Poco/Runnable.h>
 #include <Poco/StreamCopier.h>
 #include <Poco/StringTokenizer.h>
@@ -264,11 +265,21 @@ void FileServerRequestHandler::handleRequest(const HTTPRequest& request, Poco::M
     try
     {
         bool noCache = false;
+#if ENABLE_DEBUG
+        noCache = true;
+#endif
         Poco::Net::HTTPResponse response;
         Poco::URI requestUri(request.getURI());
         LOG_TRC("Fileserver request: " << requestUri.toString());
         requestUri.normalize(); // avoid .'s and ..'s
 
+        std::string path(requestUri.getPath());
+        if (path.find("loleaflet/" LOOLWSD_VERSION_HASH "/") == std::string::npos)
+        {
+            LOG_WRN("client - server version mismatch, disabling browser cache.");
+            noCache = true;
+        }
+
         std::vector<std::string> requestSegments;
         requestUri.getPathSegments(requestSegments);
         const std::string relPath = getRequestPathname(request);
@@ -533,9 +544,13 @@ std::string FileServerRequestHandler::getRequestPathname(const HTTPRequest& requ
     requestUri.normalize();
 
     std::string path(requestUri.getPath());
-
-    // Convert version back to a real file name.
-    Poco::replaceInPlace(path, std::string("/loleaflet/" LOOLWSD_VERSION_HASH "/"), std::string("/loleaflet/dist/"));
+    Poco::RegularExpression gitHashRe("/([0-9a-f]+)/");
+    std::string gitHash;
+    if (gitHashRe.extract(path, gitHash))
+    {
+        // Convert version back to a real file name.
+        Poco::replaceInPlace(path, std::string("/loleaflet" + gitHash), std::string("/loleaflet/dist/"));
+    }
 
     return path;
 }


More information about the Libreoffice-commits mailing list