add host filter

This commit is contained in:
yusing 2024-12-18 11:44:38 +08:00
parent 34d5edd6b9
commit 36069cbe6d
2 changed files with 6 additions and 0 deletions

View file

@ -7,6 +7,7 @@ type (
Filters struct {
StatusCodes LogFilter[*StatusCodeRange] `json:"status_codes"`
Method LogFilter[HTTPMethod] `json:"method"`
Host LogFilter[Host] `json:"host"`
Headers LogFilter[*HTTPHeader] `json:"headers"` // header exists or header == value
CIDR LogFilter[*CIDR] `json:"cidr"`
}

View file

@ -22,6 +22,7 @@ type (
HTTPHeader struct {
Key, Value string
}
Host string
CIDR struct{ types.CIDR }
)
@ -79,6 +80,10 @@ func (k *HTTPHeader) Fulfill(req *http.Request, res *http.Response) bool {
return false
}
func (h Host) Fulfill(req *http.Request, res *http.Response) bool {
return req.Host == string(h)
}
func (cidr CIDR) Fulfill(req *http.Request, res *http.Response) bool {
ip, _, err := net.SplitHostPort(req.RemoteAddr)
if err != nil {