From bce8fd5ea3eee42e0f6fd93dbb7ef7c7c7b80acf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Mon, 19 Apr 2021 13:11:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9B=A0=E4=B8=BAWAF?= =?UTF-8?q?=E8=80=8C=E5=AF=BC=E8=87=B4Content-Length=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E6=98=BE=E5=BC=8F=E8=AE=BE=E7=BD=AE=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/waf/requests/request.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/internal/waf/requests/request.go b/internal/waf/requests/request.go index a1b982b..28c29b9 100644 --- a/internal/waf/requests/request.go +++ b/internal/waf/requests/request.go @@ -23,13 +23,17 @@ func (this *Request) Raw() *http.Request { } func (this *Request) ReadBody(max int64) (data []byte, err error) { - data, err = ioutil.ReadAll(io.LimitReader(this.Request.Body, max)) + if this.Request.ContentLength > 0 { + data, err = ioutil.ReadAll(io.LimitReader(this.Request.Body, max)) + } return } func (this *Request) RestoreBody(data []byte) { - rawReader := bytes.NewBuffer(data) - buf := make([]byte, 1024) - io.CopyBuffer(rawReader, this.Request.Body, buf) - this.Request.Body = ioutil.NopCloser(rawReader) + if len(data) > 0 { + rawReader := bytes.NewBuffer(data) + buf := make([]byte, 1024) + _, _ = io.CopyBuffer(rawReader, this.Request.Body, buf) + this.Request.Body = ioutil.NopCloser(rawReader) + } }