[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-3' - loleaflet/src wsd/LOOLWSD.cpp

Pranav Kant pranavk at collabora.co.uk
Thu Jun 28 14:55:29 UTC 2018


 loleaflet/src/layer/tile/TileLayer.js |    4 +++-
 wsd/LOOLWSD.cpp                       |   16 ++++++++++++----
 2 files changed, 15 insertions(+), 5 deletions(-)

New commits:
commit 2faf8f590b2e1d394188d035ab713ac021473da6
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Wed Jun 27 19:53:25 2018 +0530

    wsd: in case of multiple query param, handle &attachment= correctly
    
    In case of integration with OC/NC, we have WOPISrc= as query param used
    for load balancing. So, the earlier approach failed with integration.
    
    Change-Id: Ib73f4f18eaec870dd53b67886b1b6016416a2e78
    Reviewed-on: https://gerrit.libreoffice.org/56533
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>
    Tested-by: Jan Holesovsky <kendy at collabora.com>

diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index 711eb2ef9..35d33fd1d 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -566,7 +566,9 @@ L.TileLayer = L.GridLayer.extend({
 				// due to a pdf.js issue - https://github.com/mozilla/pdf.js/issues/5397
 				// open the pdf file in a new tab so that that user can print it directly in the browser's
 				// pdf viewer
-				window.open(url + '?attachment=0', '_blank');
+				var param = wopiSrc !== '' ? '&' : '?';
+				param += 'attachment=0';
+				window.open(url + param, '_blank');
 			}
 			else {
 				this._map.fire('filedownloadready', {url: url});
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 48e915ab8..ee4f83b2a 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -2163,15 +2163,23 @@ private:
             LOG_INF("HTTP request for: " << filePath.toString());
             if (filePath.isAbsolute() && File(filePath).exists())
             {
-                int serveAsAttachment = 1;
-                if (tokens.count() >= 7)
-                    getTokenInteger(tokens[6], "attachment", serveAsAttachment);
+                const Poco::URI postRequestUri(request.getURI());
+                const Poco::URI::QueryParameters postRequestQueryParams = postRequestUri.getQueryParameters();
+
+                bool serveAsAttachment = true;
+                const auto attachmentIt = std::find_if(postRequestQueryParams.begin(),
+                                                       postRequestQueryParams.end(),
+                                                       [](const std::pair<std::string, std::string>& element) {
+                                                           return element.first == "attachment";
+                                                       });
+                if (attachmentIt != postRequestQueryParams.end())
+                    serveAsAttachment = attachmentIt->second != "0";
 
                 // Instruct browsers to download the file, not display it
                 // with the exception of SVG where we need the browser to
                 // actually show it.
                 std::string contentType = getContentType(fileName);
-                if (serveAsAttachment != 0 && contentType != "image/svg+xml")
+                if (serveAsAttachment && contentType != "image/svg+xml")
                     response.set("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
 
                 try


More information about the Libreoffice-commits mailing list