mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
set filename in Content-Disposition header
This commit is contained in:
parent
54eebf538f
commit
023a1efdf2
|
@ -218,7 +218,7 @@ func handleStaticResources2(r *mux.Router) {
|
||||||
r.PathPrefix("/seaweedfsstatic/").Handler(http.StripPrefix("/seaweedfsstatic", http.FileServer(statikFS)))
|
r.PathPrefix("/seaweedfsstatic/").Handler(http.StripPrefix("/seaweedfsstatic", http.FileServer(statikFS)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func adjustHeadersAfterHEAD(w http.ResponseWriter, r *http.Request, filename string) {
|
func adjustHeaders(w http.ResponseWriter, r *http.Request, filename string) {
|
||||||
if filename != "" {
|
if filename != "" {
|
||||||
contentDisposition := "inline"
|
contentDisposition := "inline"
|
||||||
if r.FormValue("dl") != "" {
|
if r.FormValue("dl") != "" {
|
||||||
|
|
|
@ -101,14 +101,14 @@ func (fs *FilerServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request,
|
||||||
}
|
}
|
||||||
setEtag(w, etag)
|
setEtag(w, etag)
|
||||||
|
|
||||||
|
filename := entry.Name()
|
||||||
|
adjustHeaders(w, r, filename)
|
||||||
|
|
||||||
if r.Method == "HEAD" {
|
if r.Method == "HEAD" {
|
||||||
w.Header().Set("Content-Length", strconv.FormatInt(int64(filer2.TotalSize(entry.Chunks)), 10))
|
w.Header().Set("Content-Length", strconv.FormatInt(int64(filer2.TotalSize(entry.Chunks)), 10))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
filename := entry.Name()
|
|
||||||
adjustHeadersAfterHEAD(w, r, filename)
|
|
||||||
|
|
||||||
totalSize := int64(filer2.TotalSize(entry.Chunks))
|
totalSize := int64(filer2.TotalSize(entry.Chunks))
|
||||||
|
|
||||||
if rangeReq := r.Header.Get("Range"); rangeReq == "" {
|
if rangeReq := r.Header.Get("Range"); rangeReq == "" {
|
||||||
|
|
|
@ -244,13 +244,13 @@ func writeResponseContent(filename, mimeType string, rs io.ReadSeeker, w http.Re
|
||||||
}
|
}
|
||||||
w.Header().Set("Accept-Ranges", "bytes")
|
w.Header().Set("Accept-Ranges", "bytes")
|
||||||
|
|
||||||
|
adjustHeaders(w, r, filename)
|
||||||
|
|
||||||
if r.Method == "HEAD" {
|
if r.Method == "HEAD" {
|
||||||
w.Header().Set("Content-Length", strconv.FormatInt(totalSize, 10))
|
w.Header().Set("Content-Length", strconv.FormatInt(totalSize, 10))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
adjustHeadersAfterHEAD(w, r, filename)
|
|
||||||
|
|
||||||
processRangeRequest(r, w, totalSize, mimeType, func(writer io.Writer, offset int64, size int64) error {
|
processRangeRequest(r, w, totalSize, mimeType, func(writer io.Writer, offset int64, size int64) error {
|
||||||
if _, e = rs.Seek(offset, 0); e != nil {
|
if _, e = rs.Seek(offset, 0); e != nil {
|
||||||
return e
|
return e
|
||||||
|
|
Loading…
Reference in a new issue