From b5650456493de7d4c6ded4ce7bd3eb96b1835c98 Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Wed, 30 Jun 2021 12:29:43 +0300 Subject: [PATCH] [#93] Fixed order headers set Writing headers had no effect early. Signed-off-by: Denis Kirillov --- api/handler/get.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/api/handler/get.go b/api/handler/get.go index 65f0487d2..93cc7f283 100644 --- a/api/handler/get.go +++ b/api/handler/get.go @@ -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) {