Skip to content

Commit

Permalink
Add Content-Length without Content-Encoding header
Browse files Browse the repository at this point in the history
  • Loading branch information
bmagic committed Jul 22, 2024
1 parent e62eef9 commit 830049d
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,6 @@ func (r *responsebodyrewrite) ServeHTTP(rw http.ResponseWriter, req *http.Reques

bodyBytes := wrappedWriter.buffer.Bytes()

contentEncoding := wrappedWriter.Header().Get("Content-Encoding")

if contentEncoding != "" && contentEncoding != "identity" {
if _, err := rw.Write(bodyBytes); err != nil {
r.infoLogger.Printf("unable to write body: %v", err)
}

return
}

for _, response := range r.responses {
if !response.status.Contains(wrappedWriter.code) {
continue
Expand All @@ -139,10 +129,20 @@ func (r *responsebodyrewrite) ServeHTTP(rw http.ResponseWriter, req *http.Reques
break
}

contentEncoding := wrappedWriter.Header().Get("Content-Encoding")
if contentEncoding != "" && contentEncoding != "identity" {
if _, err := rw.Write(bodyBytes); err != nil {
r.infoLogger.Printf("unable to write body: %v", err)
}
return
}

if _, err := rw.Write(bodyBytes); err != nil {
r.infoLogger.Printf("unable to write rewrited body: %v", err)
}

rw.Header().Set("Content-Length", fmt.Sprintf("%d", len(bodyBytes)))

}

// responseWriter is a wrapper around an http.ResponseWriter that allows us to intercept the response.
Expand Down

0 comments on commit 830049d

Please sign in to comment.