mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-12-14 22:56:36 +08:00
修复因为WAF而导致Content-Length没有显式设置的问题
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user