Suggest original filename when downloading
This commit is contained in:
parent
4c7023fb1f
commit
3e6ea68d07
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue