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{
|
return FileInfo{
|
||||||
Offset: 5,
|
Offset: 5,
|
||||||
Size: 20,
|
Size: 20,
|
||||||
|
MetaData: map[string]string{
|
||||||
|
"filename": "file.jpg\"evil",
|
||||||
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +58,8 @@ func TestGet(t *testing.T) {
|
||||||
Code: http.StatusOK,
|
Code: http.StatusOK,
|
||||||
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)
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue