diff --git a/get_test.go b/get_test.go index 5310854..5796dde 100644 --- a/get_test.go +++ b/get_test.go @@ -22,6 +22,9 @@ func (s getStore) GetInfo(id string) (FileInfo, error) { return FileInfo{ Offset: 5, Size: 20, + MetaData: map[string]string{ + "filename": "file.jpg\"evil", + }, }, nil } @@ -55,7 +58,8 @@ func TestGet(t *testing.T) { Code: http.StatusOK, ResBody: "hello", ResHeader: map[string]string{ - "Content-Length": "5", + "Content-Length": "5", + "Content-Disposition": `inline;filename="file.jpg\"evil"`, }, }).Run(handler, t) diff --git a/unrouted_handler.go b/unrouted_handler.go index 0e0baed..2e3c5a5 100644 --- a/unrouted_handler.go +++ b/unrouted_handler.go @@ -445,6 +445,10 @@ func (handler *UnroutedHandler) GetFile(w http.ResponseWriter, r *http.Request) return } + if filename, ok := info.MetaData["filename"]; ok { + w.Header().Set("Content-Disposition", "inline;filename="+strconv.Quote(filename)) + } + w.Header().Set("Content-Length", strconv.FormatInt(info.Offset, 10)) w.WriteHeader(http.StatusOK) io.Copy(w, src)