Skip to content

Commit

Permalink
fix: remove headers from response body (#1)
Browse files Browse the repository at this point in the history
Do not copy the whole response into the reply body but copy status headers etc.
  • Loading branch information
Thom-x committed Dec 30, 2021
1 parent 67dd3f3 commit 1923ea2
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion modsecurity.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"bytes"
"context"
"fmt"
"io"
"io/ioutil"
"net/http"
"time"
Expand Down Expand Up @@ -84,7 +85,16 @@ func (a *Modsecurity) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
defer resp.Body.Close()

if resp.StatusCode >= 400 {
resp.Write(rw)
// copy headers
for k, vv := range resp.Header {
for _, v := range vv {
rw.Header().Set(k, v)
}
}
// copy status
rw.WriteHeader(resp.StatusCode)
// copy body
io.Copy(rw, resp.Body)
return
}

Expand Down

0 comments on commit 1923ea2

Please sign in to comment.