Skip to content

Commit

Permalink
fix(middleware): avoid sending empty Content-Length (#555)
Browse files Browse the repository at this point in the history
  • Loading branch information
imlonghao authored Oct 9, 2024
1 parent f9115e9 commit d9ddd13
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/middleware/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ func (r *CustomWriter) Write(b []byte) (int, error) {
// Send delays the response to handle Cache-Status
func (r *CustomWriter) Send() (int, error) {
defer r.Buf.Reset()
r.Header().Set("Content-Length", r.Header().Get(rfc.StoredLengthHeader))
storedLength := r.Header().Get(rfc.StoredLengthHeader)
if storedLength != "" {
r.Header().Set("Content-Length", storedLength)
}
b := esi.Parse(r.Buf.Bytes(), r.Req)
if len(b) != 0 {
r.Header().Set("Content-Length", strconv.Itoa(len(b)))
Expand Down

0 comments on commit d9ddd13

Please sign in to comment.