mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-12-27 15:46:34 +08:00
实现WAF
This commit is contained in:
35
internal/waf/requests/request.go
Normal file
35
internal/waf/requests/request.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package requests
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Request struct {
|
||||
*http.Request
|
||||
BodyData []byte
|
||||
}
|
||||
|
||||
func NewRequest(raw *http.Request) *Request {
|
||||
return &Request{
|
||||
Request: raw,
|
||||
}
|
||||
}
|
||||
|
||||
func (this *Request) Raw() *http.Request {
|
||||
return this.Request
|
||||
}
|
||||
|
||||
func (this *Request) ReadBody(max int64) (data []byte, err error) {
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user