From 00ea91debb7fde677ddb7a26d395202b9740f4ef Mon Sep 17 00:00:00 2001 From: vagisha Date: Thu, 1 Feb 2024 20:40:59 -0800 Subject: [PATCH] Overwrite the Content-Disposition header in DownloadToolAction for Skyline compatibility (#393) - Use PageFlowUtil.streamFile instead of returning HttpRedirectView in DownloadToolAction - Skyline expects the 'Content-Disposition' response header value to look like this: filename="MSstatsShiny.zip". Pass this to PageFlowUtil.streamFile so that it overwrites the value already set. --- .../SkylineToolsStoreController.java | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/SkylineToolsStore/src/org/labkey/skylinetoolsstore/SkylineToolsStoreController.java b/SkylineToolsStore/src/org/labkey/skylinetoolsstore/SkylineToolsStoreController.java index 929d02a6..321a25b6 100644 --- a/SkylineToolsStore/src/org/labkey/skylinetoolsstore/SkylineToolsStoreController.java +++ b/SkylineToolsStore/src/org/labkey/skylinetoolsstore/SkylineToolsStoreController.java @@ -67,13 +67,14 @@ import org.labkey.api.util.URLHelper; import org.labkey.api.view.ActionURL; import org.labkey.api.view.HtmlView; -import org.labkey.api.view.HttpRedirectView; import org.labkey.api.view.HttpView; import org.labkey.api.view.JspView; import org.labkey.api.view.NavTree; import org.labkey.api.view.NotFoundException; import org.labkey.api.view.RedirectException; import org.labkey.api.view.UnauthorizedException; +import org.labkey.api.webdav.WebdavResource; +import org.labkey.api.webdav.WebdavService; import org.labkey.skylinetoolsstore.model.Rating; import org.labkey.skylinetoolsstore.model.SkylineTool; import org.labkey.skylinetoolsstore.view.SkylineToolDetails; @@ -105,6 +106,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; +import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; import java.util.HashSet; @@ -1101,9 +1103,28 @@ else if (toolLsid != null && "Path=/; Domain=;"); } - return new HttpRedirectView( - AppProps.getInstance().getContextPath() + "/files" + tool.lookupContainer().getPath() - + "/" + tool.getZipName()); + Container toolContainer = ContainerManager.getForId(tool.getContainerId()); + if (toolContainer == null) + { + throw new NotFoundException("Tool container not found"); + } + + org.labkey.api.util.Path path = WebdavService.getPath().append(toolContainer.getParsedPath()).append(FileContentService.FILES_LINK).append(tool.getZipName()); + WebdavResource resource = WebdavService.get().getResolver().lookup(path); + if (resource == null || !resource.isFile()) + throw new NotFoundException("Resource could not be found: " + path.toString()); + + // Issue 49580: https://www.labkey.org/MacCoss/Issue%20Tracker/issues-details.view?issueId=49580 + // Add our own 'Content-Disposition' header so that it overwrites the one set in + // ResponseHelper.setContentDisposition(HttpServletResponse response, ContentDispositionType type, @NotNull String filename) + // Skyline expects the 'Content-Disposition' header value to look like this: filename="MSstatsShiny.zip". + Map headers = Collections.singletonMap("Content-Disposition", "filename=\""+ tool.getZipName() + "\""); + PageFlowUtil.streamFile(getViewContext().getResponse(), + headers, + resource.getName(), + resource.getInputStream(getUser()), + true); + return null; } protected boolean recordDownload(HttpServletRequest httpServletRequest, int toolId)