diff --git a/support/response.go b/support/response.go index ae93704..644ab2d 100644 --- a/support/response.go +++ b/support/response.go @@ -24,6 +24,7 @@ type RawResponse struct { } type FileResponse struct { + headers [][2]string disposition string name string } @@ -78,12 +79,17 @@ func (this FileResponse) Get(path ...string) req.GlobalParams { } func (this FileResponse) Send(w http.ResponseWriter, r *http.Request) { - if this.Get("disposition").String() != "" { - w.Header().Set("Content-Disposition", `attachment; filename="`+this.Get("disposition").String()+`"`) - } if _, err := os.Stat(this.Get("name").String()); err != nil && os.IsNotExist(err) { w.WriteHeader(http.StatusNotFound) } else { + if this.Get("disposition").String() != "" { + w.Header().Set("Content-Disposition", `attachment; filename="`+this.Get("disposition").String()+`"`) + } + + for i := 0; i < len(this.headers); i++ { + w.Header().Set(this.headers[i][0], this.headers[i][1]) + } + http.ServeFile(w, r, this.Get("name").String()) } } @@ -96,8 +102,8 @@ func NewRawResponse(b []byte, headers ...[2]string) req.HttpResponse { return &RawResponse{raw: b, headers: headers} } -func NewFileResponse(name string, disposition string) req.HttpResponse { - return &FileResponse{name: name, disposition: disposition} +func NewFileResponse(name string, disposition string, headers ...[2]string) req.HttpResponse { + return &FileResponse{name: name, disposition: disposition, headers: headers} } func NewJsonResponse(b []byte) req.HttpResponse {