fix(copy): copy from driver that return writer (close #4291)

This commit is contained in:
Andy Hsu
2023-05-26 21:54:57 +08:00
parent 6b97b4eb20
commit b2f5757f8d
7 changed files with 91 additions and 77 deletions

View File

@ -81,8 +81,21 @@ func Proxy(w http.ResponseWriter, r *http.Request, link *model.Link, file model.
w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"; filename*=UTF-8''%s`, filename, url.PathEscape(filename)))
http.ServeContent(w, r, file.GetName(), fileStat.ModTime(), f)
return nil
} else if link.Handle != nil {
return link.Handle(w, r)
} else if link.Writer != nil {
if link.Header != nil {
for h, v := range link.Header {
w.Header()[h] = v
}
}
if cd := w.Header().Get("Content-Disposition"); cd == "" {
w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"; filename*=UTF-8''%s`, file.GetName(), url.PathEscape(file.GetName())))
}
if link.Status == 0 {
w.WriteHeader(http.StatusOK)
} else {
w.WriteHeader(link.Status)
}
return link.Writer(w)
} else {
req, err := http.NewRequest(r.Method, link.URL, nil)
if err != nil {