From 5078a922305faec53dc00f24a7b62d39af4b5dd4 Mon Sep 17 00:00:00 2001 From: MAUGIN Thomas Date: Thu, 30 Dec 2021 15:49:10 +0100 Subject: [PATCH] fix: copy response into reply Do not copy the whole response into the reply body but copy status headers etc. --- modsecurity.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/modsecurity.go b/modsecurity.go index 72755d5..29b3050 100644 --- a/modsecurity.go +++ b/modsecurity.go @@ -5,6 +5,7 @@ import ( "bytes" "context" "fmt" + "io" "io/ioutil" "net/http" "time" @@ -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 }