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{
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)

View File

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