Ver código fonte

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

Sebastian Stenzel 8 anos atrás
pai
commit
7753d1f0e7

+ 1 - 1
main/filesystem-crypto/pom.xml

@@ -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>

+ 5 - 0
main/frontend-webdav/src/main/java/org/cryptomator/frontend/webdav/jackrabbitservlet/DavFile.java

@@ -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);

+ 2 - 0
main/frontend-webdav/src/main/java/org/cryptomator/frontend/webdav/jackrabbitservlet/DavFileWithRange.java

@@ -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);