[Libreoffice-commits] online.git: 2 commits - loleaflet/js wsd/FileServer.cpp wsd/LOOLWSD.cpp

Michael Meeks (via logerrit) logerrit at kemper.freedesktop.org
Tue Apr 28 14:37:49 UTC 2020


 loleaflet/js/global.js |   16 +++++++++++++---
 wsd/FileServer.cpp     |   27 +++++++++++++++++++++++++--
 wsd/LOOLWSD.cpp        |    2 +-
 3 files changed, 39 insertions(+), 6 deletions(-)

New commits:
commit 5721f5855094f3408ad7426cf477415c2263fc0b
Author:     Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Tue Apr 28 15:18:24 2020 +0100
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Tue Apr 28 16:37:37 2020 +0200

    Improve error handling on failure to fetch session id.
    
    Change-Id: I8314fad3566f70abab78a6592a99d70597e40706
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/93078
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/loleaflet/js/global.js b/loleaflet/js/global.js
index 1e09a86e0..c3c8343ad 100644
--- a/loleaflet/js/global.js
+++ b/loleaflet/js/global.js
@@ -311,9 +311,19 @@
 			req.responseType = 'text';
 			req.addEventListener('load', function() {
 				console.debug('got session: ' + this.responseText);
-				that.sessionId = this.responseText;
-				that.readyState = 1;
-				that.onopen();
+				if (this.responseText.indexOf('\n') >= 0)
+				{
+					console.debug('Error: failed to fetch session id!');
+					that.onerror();
+					that.onclose();
+					that.readyState = 3;
+				}
+				else
+				{
+					that.sessionId = this.responseText;
+					that.readyState = 1;
+					that.onopen();
+				}
 			});
 			req.send('');
 		};
commit c9ed710518725872a583ea31cac3b60178daa540
Author:     Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Tue Apr 28 15:17:23 2020 +0100
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Tue Apr 28 16:37:29 2020 +0200

    Proxy: convert ProxyPrefix to a full URL.
    
    Thus encoding the actual proxy's http/https state.
    
    Change-Id: Ia7d5b8fb9379364b6c10a2c84d609f49e215ccb1
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/93077
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/wsd/FileServer.cpp b/wsd/FileServer.cpp
index 8073860c2..99ac332b3 100644
--- a/wsd/FileServer.cpp
+++ b/wsd/FileServer.cpp
@@ -647,15 +647,38 @@ namespace {
         if (!request.has("ProxyPrefix"))
             return LOOLWSD::ServiceRoot;
         std::string proxyPrefix = request.get("ProxyPrefix", "");
+
+        // skip url to the root path.
+        size_t pos = proxyPrefix.find("://");
+        if (pos != std::string::npos) {
+            pos = proxyPrefix.find("/", pos + 3);
+            if (pos != std::string::npos)
+                proxyPrefix = proxyPrefix.substr(pos);
+            else
+                LOG_DBG("Unusual proxy prefix '" << proxyPrefix << "'");
+        } else
+            LOG_DBG("No http[s]:// in unusual proxy prefix '" << proxyPrefix);
         return proxyPrefix;
     }
+
+    std::string getWebSocketUrl(const HTTPRequest &request)
+    {
+        bool ssl = (LOOLWSD::isSSLEnabled() || LOOLWSD::isSSLTermination());
+        std::string proxyPrefix = request.get("ProxyPrefix", "");
+        std::string serverName = LOOLWSD::ServerName.empty() ? request.getHost() : LOOLWSD::ServerName;
+        if (proxyPrefix.size() > 0)
+        {
+            ssl = !strcmp(proxyPrefix.c_str(), "https://");
+            serverName = request.getHost();
+        }
+        return (ssl ? "wss://" : "ws://") + serverName;
+    }
 }
 
 void FileServerRequestHandler::preprocessFile(const HTTPRequest& request, Poco::MemoryInputStream& message,
                                               const std::shared_ptr<StreamSocket>& socket)
 {
-    const auto host = ((LOOLWSD::isSSLEnabled() || LOOLWSD::isSSLTermination()) ? "wss://" : "ws://")
-                    + (LOOLWSD::ServerName.empty() ? request.getHost() : LOOLWSD::ServerName);
+    const auto host = getWebSocketUrl(request);
     const Poco::URI::QueryParameters params = Poco::URI(request.getURI()).getQueryParameters();
 
     // Is this a file we read at startup - if not; its not for serving.
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index b996c9877..329051698 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -2504,7 +2504,7 @@ private:
             + (LOOLWSD::ServerName.empty() ? request.getHost() : LOOLWSD::ServerName)
             + LOOLWSD::ServiceRoot;
         if (request.has("ProxyPrefix"))
-            srvUrl += request["ProxyPrefix"];
+            srvUrl = request["ProxyPrefix"];
         Poco::replaceInPlace(xml, std::string("%SRV_URI%"), srvUrl);
 
         // TODO: Refactor this to some common handler.


More information about the Libreoffice-commits mailing list