修复因为WAF而导致Content-Length没有显式设置的问题

This commit is contained in:
刘祥超
2021-04-19 13:11:27 +08:00
parent d1fcbb46a3
commit bce8fd5ea3

View File

@@ -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)
}
}