diff options
author | Michael Meeks <michael.meeks@collabora.com> | 2020-05-06 17:02:51 +0100 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2020-05-06 23:12:12 +0200 |
commit | 18c4301a1f26e5630b24db532a532baafb6cd57f (patch) | |
tree | 2d16d8891e3b218f605b8ad1421b5e7fe227ee60 /wsd/FileServer.cpp | |
parent | Android: fix that app shows temporary file name "LibreOffice..." (diff) | |
download | online-18c4301a1f26e5630b24db532a532baafb6cd57f.tar.gz online-18c4301a1f26e5630b24db532a532baafb6cd57f.zip |
Proxy: re-factor proxy handling into ServerURL and cleanup copy/paste.
Also adds ServiceRoot handling for clipboard.
Change-Id: I7bc6591130fcc7d693e59ab8561fb9e99f4e93d5
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/93578
Tested-by: Michael Meeks <michael.meeks@collabora.com>
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
Diffstat (limited to 'wsd/FileServer.cpp')
-rw-r--r-- | wsd/FileServer.cpp | 54 |
1 files changed, 3 insertions, 51 deletions
diff --git a/wsd/FileServer.cpp b/wsd/FileServer.cpp index 888509591c..8809a582ac 100644 --- a/wsd/FileServer.cpp +++ b/wsd/FileServer.cpp @@ -43,6 +43,7 @@ #include <Crypto.hpp> #include "FileServer.hpp" #include "LOOLWSD.hpp" +#include "ServerURL.hpp" #include <Log.hpp> #include <Protocol.hpp> #include <Util.hpp> @@ -641,61 +642,12 @@ constexpr char BRANDING_UNSUPPORTED[] = "branding-unsupported"; #endif namespace { - /// Very simple splitting of proxy URLs without fear of escaping or validation. - class ProxyURL { - std::string _schemeAuthority; - std::string _pathPlus; - public: - ProxyURL(const HTTPRequest &request) - { - // The user can override the ServerRoot with a new prefix. - if (_pathPlus.size() <= 0) - _pathPlus = LOOLWSD::ServiceRoot; - - if (_schemeAuthority.size() <= 0) - { - bool ssl = (LOOLWSD::isSSLEnabled() || LOOLWSD::isSSLTermination()); - std::string serverName = LOOLWSD::ServerName.empty() ? request.getHost() : LOOLWSD::ServerName; - _schemeAuthority = (ssl ? "wss://" : "ws://") + serverName; - } - - // A well formed ProxyPrefix will override it. - std::string url = request.get("ProxyPrefix", ""); - if (url.size() <= 0) - return; - - size_t pos = url.find("://"); - if (pos != std::string::npos) { - pos = url.find("/", pos + 3); - if (pos != std::string::npos) - { - _schemeAuthority = url.substr(0, pos); - _pathPlus = url.substr(pos); - return; - } - else - LOG_ERR("Unusual proxy prefix '" << url << "'"); - } else - LOG_ERR("No http[s]:// in unusual proxy prefix '" << url << "'"); - - } - - std::string getResponseRoot() const - { - return _pathPlus; - } - - std::string getWebSocketUrl() const - { - return _schemeAuthority; - } - }; } void FileServerRequestHandler::preprocessFile(const HTTPRequest& request, Poco::MemoryInputStream& message, const std::shared_ptr<StreamSocket>& socket) { - ProxyURL cnxDetails(request); + ServerURL cnxDetails(request); const Poco::URI::QueryParameters params = Poco::URI(request.getURI()).getQueryParameters(); @@ -963,7 +915,7 @@ void FileServerRequestHandler::preprocessAdminFile(const HTTPRequest& request,co if (!FileServerRequestHandler::isAdminLoggedIn(request, response)) throw Poco::Net::NotAuthenticatedException("Invalid admin login"); - ProxyURL cnxDetails(request); + ServerURL cnxDetails(request); std::string responseRoot = cnxDetails.getResponseRoot(); static const std::string scriptJS("<script src=\"%s/loleaflet/" LOOLWSD_VERSION_HASH "/%s.js\"></script>"); |