If GET request is made by a browser, the file in question is downloaded instead of being executed. Issue #318

This commit is contained in:
Sebastian Stenzel
2016-08-09 17:35:17 +02:00
parent d7c6c24932
commit 7753d1f0e7
3 changed files with 8 additions and 1 deletions

View File

@@ -19,7 +19,7 @@
<properties>
<bouncycastle.version>1.51</bouncycastle.version>
<sivmode.version>1.0.4</sivmode.version>
<sivmode.version>1.0.7</sivmode.version>
</properties>
<dependencies>

View File

@@ -40,6 +40,9 @@ import com.google.common.io.ByteStreams;
class DavFile extends DavNode<FileLocator> {
private static final Logger LOG = LoggerFactory.getLogger(DavFile.class);
protected static final String CONTENT_TYPE_VALUE = "application/octet-stream";
protected static final String CONTENT_DISPOSITION_HEADER = "Content-Disposition";
protected static final String CONTENT_DISPOSITION_VALUE = "attachment";
public DavFile(FilesystemResourceFactory factory, LockManager lockManager, DavSession session, FileLocator node) {
super(factory, lockManager, session, node);
@@ -56,6 +59,8 @@ class DavFile extends DavNode<FileLocator> {
if (!outputContext.hasStream()) {
return;
}
outputContext.setContentType(CONTENT_TYPE_VALUE);
outputContext.setProperty(CONTENT_DISPOSITION_HEADER, CONTENT_DISPOSITION_VALUE);
try (ReadableFile src = node.openReadable(); WritableByteChannel dst = Channels.newChannel(outputContext.getOutputStream())) {
outputContext.setContentLength(src.size());
ByteStreams.copy(src, dst);

View File

@@ -57,6 +57,8 @@ class DavFileWithRange extends DavFile {
final Long rangeLength = range.getRight() - range.getLeft() + 1;
outputContext.setContentLength(rangeLength);
outputContext.setProperty(HttpHeader.CONTENT_RANGE.asString(), contentRangeResponseHeader(range.getLeft(), range.getRight(), contentLength));
outputContext.setContentType(CONTENT_TYPE_VALUE);
outputContext.setProperty(CONTENT_DISPOSITION_HEADER, CONTENT_DISPOSITION_VALUE);
src.position(range.getLeft());
InputStream limitedIn = ByteStreams.limit(Channels.newInputStream(src), rangeLength);
ByteStreams.copy(limitedIn, out);