Skip to content

Commit

Permalink
Fix wrong Content-Length after ESI parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
p0358 authored and darkweak committed Feb 8, 2024
1 parent 3acd7f2 commit 4877fc2
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions pkg/middleware/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package middleware
import (
"bytes"
"net/http"
"strconv"
"sync"

"github.com/darkweak/go-esi/esi"
Expand Down Expand Up @@ -79,13 +80,9 @@ func (r *CustomWriter) Write(b []byte) (int, error) {

// Send delays the response to handle Cache-Status
func (r *CustomWriter) Send() (int, error) {
contentLength := r.Header().Get(rfc.StoredLengthHeader)
if contentLength != "" {
r.Header().Set("Content-Length", contentLength)
}

defer r.Buf.Reset()
b := esi.Parse(r.Buf.Bytes(), r.Req)
r.Header().Set("Content-Length", strconv.Itoa(len(b)))
r.Header().Del(rfc.StoredLengthHeader)
r.Header().Del(rfc.StoredTTLHeader)

Expand Down

0 comments on commit 4877fc2

Please sign in to comment.