Yet another header to prevent browsers from guessing mime types. Kudos to @LukasReschke

This commit is contained in:
Sebastian Stenzel
2016-08-09 17:42:24 +02:00
parent 7753d1f0e7
commit 93d3eca0ab
2 changed files with 4 additions and 0 deletions
@@ -43,6 +43,8 @@ class DavFile extends DavNode<FileLocator> {
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";
protected static final String X_CONTENT_TYPE_OPTIONS_HEADER = "X-Content-Type-Options";
protected static final String X_CONTENT_TYPE_OPTIONS_VALUE = "nosniff";
public DavFile(FilesystemResourceFactory factory, LockManager lockManager, DavSession session, FileLocator node) {
super(factory, lockManager, session, node);
@@ -61,6 +63,7 @@ class DavFile extends DavNode<FileLocator> {
}
outputContext.setContentType(CONTENT_TYPE_VALUE);
outputContext.setProperty(CONTENT_DISPOSITION_HEADER, CONTENT_DISPOSITION_VALUE);
outputContext.setProperty(X_CONTENT_TYPE_OPTIONS_HEADER, X_CONTENT_TYPE_OPTIONS_VALUE);
try (ReadableFile src = node.openReadable(); WritableByteChannel dst = Channels.newChannel(outputContext.getOutputStream())) {
outputContext.setContentLength(src.size());
ByteStreams.copy(src, dst);
@@ -59,6 +59,7 @@ class DavFileWithRange extends DavFile {
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);
outputContext.setProperty(X_CONTENT_TYPE_OPTIONS_HEADER, X_CONTENT_TYPE_OPTIONS_VALUE);
src.position(range.getLeft());
InputStream limitedIn = ByteStreams.limit(Channels.newInputStream(src), rangeLength);
ByteStreams.copy(limitedIn, out);