[#93] Fixed order headers set

Writing headers had no effect early.

Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
Denis Kirillov 2021-06-30 12:29:43 +03:00
parent d2bed40c19
commit b565045649

View file

@ -30,11 +30,13 @@ func newDetector(w io.Writer) *detector {
func (d *detector) Write(data []byte) (int, error) {
d.Once.Do(func() {
d.contentType = http.DetectContentType(data)
if rw, ok := d.Writer.(http.ResponseWriter); ok {
rw.WriteHeader(http.StatusOK)
if len(rw.Header().Get(api.ContentType)) == 0 {
rw.Header().Set(api.ContentType, d.contentType)
}
}
d.contentType = http.DetectContentType(data)
})
return d.Writer.Write(data)
@ -136,15 +138,14 @@ func (h *handler) GetObjectHandler(w http.ResponseWriter, r *http.Request) {
writeError(w, r, h.log, "could not parse range header", rid, bkt, obj, err)
return
}
if inf.ContentType, err = h.contentTypeFetcherWithRange(r.Context(), w, inf, params); err != nil {
writeError(w, r, h.log, "could not get object", rid, bkt, obj, err)
return
}
writeHeaders(w.Header(), inf)
if params != nil {
writeRangeHeaders(w, params, inf.Size)
}
if inf.ContentType, err = h.contentTypeFetcherWithRange(r.Context(), w, inf, params); err != nil {
writeError(w, r, h.log, "could not get object", rid, bkt, obj, err)
return
}
}
func writeRangeHeaders(w http.ResponseWriter, params *layer.RangeParams, size int64) {