Skip to content

Commit 00ea91d

Browse files
authored
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.
1 parent ca1e956 commit 00ea91d

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

SkylineToolsStore/src/org/labkey/skylinetoolsstore/SkylineToolsStoreController.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,14 @@
6767
import org.labkey.api.util.URLHelper;
6868
import org.labkey.api.view.ActionURL;
6969
import org.labkey.api.view.HtmlView;
70-
import org.labkey.api.view.HttpRedirectView;
7170
import org.labkey.api.view.HttpView;
7271
import org.labkey.api.view.JspView;
7372
import org.labkey.api.view.NavTree;
7473
import org.labkey.api.view.NotFoundException;
7574
import org.labkey.api.view.RedirectException;
7675
import org.labkey.api.view.UnauthorizedException;
76+
import org.labkey.api.webdav.WebdavResource;
77+
import org.labkey.api.webdav.WebdavService;
7778
import org.labkey.skylinetoolsstore.model.Rating;
7879
import org.labkey.skylinetoolsstore.model.SkylineTool;
7980
import org.labkey.skylinetoolsstore.view.SkylineToolDetails;
@@ -105,6 +106,7 @@
105106
import java.util.ArrayList;
106107
import java.util.Arrays;
107108
import java.util.Calendar;
109+
import java.util.Collections;
108110
import java.util.Enumeration;
109111
import java.util.HashMap;
110112
import java.util.HashSet;
@@ -1101,9 +1103,28 @@ else if (toolLsid != null &&
11011103
"Path=/; Domain=;");
11021104
}
11031105

1104-
return new HttpRedirectView(
1105-
AppProps.getInstance().getContextPath() + "/files" + tool.lookupContainer().getPath()
1106-
+ "/" + tool.getZipName());
1106+
Container toolContainer = ContainerManager.getForId(tool.getContainerId());
1107+
if (toolContainer == null)
1108+
{
1109+
throw new NotFoundException("Tool container not found");
1110+
}
1111+
1112+
org.labkey.api.util.Path path = WebdavService.getPath().append(toolContainer.getParsedPath()).append(FileContentService.FILES_LINK).append(tool.getZipName());
1113+
WebdavResource resource = WebdavService.get().getResolver().lookup(path);
1114+
if (resource == null || !resource.isFile())
1115+
throw new NotFoundException("Resource could not be found: " + path.toString());
1116+
1117+
// Issue 49580: https://www.labkey.org/MacCoss/Issue%20Tracker/issues-details.view?issueId=49580
1118+
// Add our own 'Content-Disposition' header so that it overwrites the one set in
1119+
// ResponseHelper.setContentDisposition(HttpServletResponse response, ContentDispositionType type, @NotNull String filename)
1120+
// Skyline expects the 'Content-Disposition' header value to look like this: filename="MSstatsShiny.zip".
1121+
Map<String, String> headers = Collections.singletonMap("Content-Disposition", "filename=\""+ tool.getZipName() + "\"");
1122+
PageFlowUtil.streamFile(getViewContext().getResponse(),
1123+
headers,
1124+
resource.getName(),
1125+
resource.getInputStream(getUser()),
1126+
true);
1127+
return null;
11071128
}
11081129

11091130
protected boolean recordDownload(HttpServletRequest httpServletRequest, int toolId)

0 commit comments

Comments
 (0)