[Libreoffice-commits] online.git: wsd/ServerURL.hpp

Michael Meeks (via logerrit) logerrit at kemper.freedesktop.org
Thu May 7 19:00:25 UTC 2020


 wsd/ServerURL.hpp |   18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

New commits:
commit 526dd304b7625087d54a75df034058c493321999
Author:     Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Thu May 7 17:30:04 2020 +0100
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Thu May 7 21:00:04 2020 +0200

    Proxy: getSubURLForEndpoint - don't return wss:// URLs in error.
    
    Separate _ssl and _websocket state and construct the URLs from them.
    
    Change-Id: Ida4eee868c7815eb68e3029682d603d13d193153
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/93669
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/wsd/ServerURL.hpp b/wsd/ServerURL.hpp
index 3e96fff98..647ca966d 100644
--- a/wsd/ServerURL.hpp
+++ b/wsd/ServerURL.hpp
@@ -19,7 +19,8 @@
  */
 class ServerURL
 {
-    std::string _schemeProtocol;
+    bool        _ssl;
+    bool        _websocket;
     std::string _schemeAuthority;
     std::string _pathPlus;
 public:
@@ -38,9 +39,9 @@ public:
         // The user can override the ServerRoot with a new prefix.
         _pathPlus = LOOLWSD::ServiceRoot;
 
-        bool ssl = (LOOLWSD::isSSLEnabled() || LOOLWSD::isSSLTermination());
+        _ssl = (LOOLWSD::isSSLEnabled() || LOOLWSD::isSSLTermination());
+        _websocket = true;
         std::string serverName = LOOLWSD::ServerName.empty() ? host : LOOLWSD::ServerName;
-        _schemeProtocol = (ssl ? "wss://" : "ws://");
         _schemeAuthority = serverName;
 
         // A well formed ProxyPrefix will override it.
@@ -54,7 +55,9 @@ public:
             auto hostEndPos = url.find("/", pos);
             if (hostEndPos != std::string::npos)
             {
-                _schemeProtocol = url.substr(0, pos);
+                _websocket = false;
+                std::string schemeProtocol = url.substr(0, pos);
+                _ssl = (schemeProtocol != "http://");
                 _schemeAuthority = url.substr(pos, hostEndPos - pos);
                 _pathPlus = url.substr(hostEndPos);
                 return;
@@ -72,12 +75,15 @@ public:
 
     std::string getWebSocketUrl() const
     {
-        return _schemeProtocol + _schemeAuthority;
+        std::string schemeProtocol = (_websocket ? "ws" : "http");
+        if (_ssl)
+            schemeProtocol += "s";
+        return schemeProtocol + "://" + _schemeAuthority;
     }
 
     std::string getSubURLForEndpoint(const std::string &path) const
     {
-        return _schemeProtocol + _schemeAuthority + _pathPlus + path;
+        return std::string("http") + (_ssl ? "s" : "") + "://" + _schemeAuthority + _pathPlus + path;
     }
 };
 


More information about the Libreoffice-commits mailing list