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

New commits:
commit 8156c2a8f13a61a65f7f9cc017c3a66d33ac7457
Author: Pranav Kant <pran...@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/56531
    Reviewed-by: pranavk <pran...@collabora.co.uk>
    Tested-by: pranavk <pran...@collabora.co.uk>

diff --git a/loleaflet/src/layer/tile/TileLayer.js 
b/loleaflet/src/layer/tile/TileLayer.js
index 1f0d283ec..1a7cb886f 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -578,7 +578,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 25ec59258..b7a954869 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -2210,15 +2210,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
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to