Skip to content

Commit

Permalink
Move content-length to end
Browse files Browse the repository at this point in the history
  • Loading branch information
eladlachmi committed Oct 8, 2023
1 parent ebe3602 commit 33c9624
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/gateway/operations/getobject.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func (controller *GetObject) Handle(w http.ResponseWriter, req *http.Request, o
// by here, we have a range we can use.
}

var contentLength int64
if rangeSpec == "" || err != nil {
// assemble a response body (range-less query)
data, err = o.BlockStore.Get(req.Context(), block.ObjectPointer{
Expand All @@ -95,7 +96,7 @@ func (controller *GetObject) Handle(w http.ResponseWriter, req *http.Request, o
_ = o.EncodeError(w, req, err, gatewayerrors.Codes.ToAPIErr(gatewayerrors.ErrInternalError))
return
}
o.SetHeader(w, "Content-Length", fmt.Sprintf("%d", entry.Size))
contentLength = entry.Size
} else {
data, err = o.BlockStore.GetRange(req.Context(), block.ObjectPointer{
StorageNamespace: o.Repository.StorageNamespace,
Expand All @@ -108,10 +109,11 @@ func (controller *GetObject) Handle(w http.ResponseWriter, req *http.Request, o
}
contentRange := fmt.Sprintf("bytes %d-%d/%d", rng.StartOffset, rng.EndOffset, entry.Size)
o.SetHeader(w, "Content-Range", contentRange)
o.SetHeader(w, "Content-Length", fmt.Sprintf("%d", rng.Size()))
contentLength = rng.Size()
w.WriteHeader(http.StatusPartialContent)
}

o.SetHeader(w, "Content-Length", fmt.Sprintf("%d", contentLength))
o.SetHeader(w, "X-Content-Type-Options", "nosniff")
o.SetHeader(w, "X-Frame-Options", "SAMEORIGIN")
o.SetHeader(w, "Content-Security-Policy", "default-src 'none'")
Expand Down

0 comments on commit 33c9624

Please sign in to comment.