From f101ad6855ae110046b9c16ce3c276addf75837e Mon Sep 17 00:00:00 2001 From: Alexander Kovalenko Date: Thu, 12 May 2016 13:11:27 +0300 Subject: [PATCH] Fix Content-Disposition header; add dl=(0|1) URI param to use inline (default) or attachment --- go/weed/weed_server/volume_server_handlers_read.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/go/weed/weed_server/volume_server_handlers_read.go b/go/weed/weed_server/volume_server_handlers_read.go index 0bfe06d42..5f3199738 100644 --- a/go/weed/weed_server/volume_server_handlers_read.go +++ b/go/weed/weed_server/volume_server_handlers_read.go @@ -197,7 +197,13 @@ func writeResponseContent(filename, mimeType string, rs io.ReadSeeker, w http.Re w.Header().Set("Content-Type", mimeType) } if filename != "" { - w.Header().Set("Content-Disposition", `filename="`+fileNameEscaper.Replace(filename)+`"`) + contentDisposition := "inline" + if r.FormValue("dl") != "" { + if dl, _ := strconv.ParseBool(r.FormValue("dl")); dl { + contentDisposition = "attachment" + } + } + w.Header().Set("Content-Disposition", contentDisposition+`; filename="`+fileNameEscaper.Replace(filename)+`"`) } w.Header().Set("Accept-Ranges", "bytes") if r.Method == "HEAD" {