forked from TrueCloudLab/frostfs-s3-gw
[#93] Fixed order headers set
Writing headers had no effect early. Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
parent
d2bed40c19
commit
b565045649
1 changed files with 8 additions and 7 deletions
|
@ -30,11 +30,13 @@ func newDetector(w io.Writer) *detector {
|
||||||
|
|
||||||
func (d *detector) Write(data []byte) (int, error) {
|
func (d *detector) Write(data []byte) (int, error) {
|
||||||
d.Once.Do(func() {
|
d.Once.Do(func() {
|
||||||
|
d.contentType = http.DetectContentType(data)
|
||||||
if rw, ok := d.Writer.(http.ResponseWriter); ok {
|
if rw, ok := d.Writer.(http.ResponseWriter); ok {
|
||||||
rw.WriteHeader(http.StatusOK)
|
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)
|
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)
|
writeError(w, r, h.log, "could not parse range header", rid, bkt, obj, err)
|
||||||
return
|
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)
|
writeHeaders(w.Header(), inf)
|
||||||
if params != nil {
|
if params != nil {
|
||||||
writeRangeHeaders(w, params, inf.Size)
|
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) {
|
func writeRangeHeaders(w http.ResponseWriter, params *layer.RangeParams, size int64) {
|
||||||
|
|
Loading…
Reference in a new issue