Skip to content

Commit 3a13902

Browse files
authored
fix: remove headers from response body (#1)
Do not copy the whole response into the reply body but copy status headers etc.
1 parent ba93672 commit 3a13902

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

modsecurity.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"bytes"
66
"context"
77
"fmt"
8+
"io"
89
"io/ioutil"
910
"net/http"
1011
"time"
@@ -84,7 +85,16 @@ func (a *Modsecurity) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
8485
defer resp.Body.Close()
8586

8687
if resp.StatusCode >= 400 {
87-
resp.Write(rw)
88+
// copy headers
89+
for k, vv := range resp.Header {
90+
for _, v := range vv {
91+
rw.Header().Set(k, v)
92+
}
93+
}
94+
// copy status
95+
rw.WriteHeader(resp.StatusCode)
96+
// copy body
97+
io.Copy(rw, resp.Body)
8898
return
8999
}
90100

0 commit comments

Comments
 (0)