Suggest original filename when downloading

This commit is contained in:
Marius 2016-04-19 11:22:32 +02:00
parent 4c7023fb1f
commit 3e6ea68d07
2 changed files with 9 additions and 1 deletions

View File

@ -22,6 +22,9 @@ func (s getStore) GetInfo(id string) (FileInfo, error) {
return FileInfo{ return FileInfo{
Offset: 5, Offset: 5,
Size: 20, Size: 20,
MetaData: map[string]string{
"filename": "file.jpg\"evil",
},
}, nil }, nil
} }
@ -56,6 +59,7 @@ func TestGet(t *testing.T) {
ResBody: "hello", ResBody: "hello",
ResHeader: map[string]string{ ResHeader: map[string]string{
"Content-Length": "5", "Content-Length": "5",
"Content-Disposition": `inline;filename="file.jpg\"evil"`,
}, },
}).Run(handler, t) }).Run(handler, t)

View File

@ -445,6 +445,10 @@ func (handler *UnroutedHandler) GetFile(w http.ResponseWriter, r *http.Request)
return 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.Header().Set("Content-Length", strconv.FormatInt(info.Offset, 10))
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
io.Copy(w, src) io.Copy(w, src)