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

Michael Meeks michael.meeks at collabora.com
Sat Mar 11 22:29:39 UTC 2017


 wsd/FileServer.cpp |   26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

New commits:
commit 71a1e188a75922df0166b84cd4c57a873555b104
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Sat Mar 11 22:28:59 2017 +0000

    Handle If-None-Match / ETag (hopefully) - hard to test ...

diff --git a/wsd/FileServer.cpp b/wsd/FileServer.cpp
index 1de7813..4fdf14d 100644
--- a/wsd/FileServer.cpp
+++ b/wsd/FileServer.cpp
@@ -12,6 +12,7 @@
 #include <string>
 #include <vector>
 
+#include <Poco/DateTime.h>
 #include <Poco/DateTimeFormat.h>
 #include <Poco/DateTimeFormatter.h>
 #include <Poco/Exception.h>
@@ -168,6 +169,31 @@ void FileServerRequestHandler::handleRequest(const HTTPRequest& request, Poco::M
             else
                 mimeType = "text/plain";
 
+            auto it = request.find("If-None-Match");
+            if (it != request.end())
+            {
+                // if ETags match avoid re-sending the file.
+                if (!it->second.compare("\"" LOOLWSD_VERSION_HASH "\""))
+                {
+                    // TESTME: harder ... - do we even want ETag support ?
+                    std::ostringstream oss;
+                    Poco::Timestamp nowTs;
+                    Poco::DateTime now(nowTs);
+                    Poco::DateTime later(now.utcTime(), int64_t(1000)*1000 * 60 * 60 * 24 * 128);
+                    oss << "HTTP/1.1 304 Not Modified\r\n"
+                        << "Date: " << Poco::DateTimeFormatter::format(
+                            now, Poco::DateTimeFormat::HTTP_FORMAT) << "\r\n"
+                        << "Expires: " << Poco::DateTimeFormatter::format(
+                            later, Poco::DateTimeFormat::HTTP_FORMAT) << "\r\n"
+                        << "User-Agent: LOOLWSD WOPI Agent\r\n"
+                        << "Cache-Control: max-age=11059200\r\n"
+                        << "\r\n";
+                    socket->sendHttpResponse(oss.str());
+                    socket->shutdown();
+                    return;
+                }
+            }
+
             HttpHelper::sendFile(socket, filepath, mimeType);
         }
     }


More information about the Libreoffice-commits mailing list