Added Content-Disposition header in mediaapi's responses. matrix-org/dendrite#628

This commit is contained in:
behouba 2019-01-23 22:25:48 +03:00
parent 1e495d4578
commit e5eac51d88

View file

@ -305,6 +305,10 @@ func (r *downloadRequest) respondFromLocalFile(
}).Info("Responding with file") }).Info("Responding with file")
responseFile = file responseFile = file
responseMetadata = r.MediaMetadata responseMetadata = r.MediaMetadata
if len(responseMetadata.UploadName) > 0 {
w.Header().Set("Content-Disposition", fmt.Sprintf(`inline; filename*=utf-8"%s"`, responseMetadata.UploadName))
}
} }
w.Header().Set("Content-Type", string(responseMetadata.ContentType)) w.Header().Set("Content-Type", string(responseMetadata.ContentType))
@ -316,10 +320,6 @@ func (r *downloadRequest) respondFromLocalFile(
" object-src 'self';" " object-src 'self';"
w.Header().Set("Content-Security-Policy", contentSecurityPolicy) w.Header().Set("Content-Security-Policy", contentSecurityPolicy)
if len(responseMetadata.UploadName) > 0 && !r.IsThumbnailRequest {
w.Header().Set("Content-Disposition", fmt.Sprintf(`inline; filename*=utf-8"%s"`, responseMetadata.UploadName))
}
if _, err := io.Copy(w, responseFile); err != nil { if _, err := io.Copy(w, responseFile); err != nil {
return nil, errors.Wrap(err, "failed to copy from cache") return nil, errors.Wrap(err, "failed to copy from cache")
} }