take method from header

This commit is contained in:
alteredCoder 2023-07-25 15:24:36 +02:00
parent a326ffbb1e
commit c17b103f06

View file

@ -11,6 +11,13 @@ import (
"github.com/google/uuid" "github.com/google/uuid"
) )
const (
URIHeaderName = "X-Crowdsec-Waf-Uri"
VerbHeaderName = "X-Crowdsec-Waf-Verb"
HostHeaderName = "X-Crowdsec-Waf-Host"
IPHeaderName = "X-Crowdsec-Waf-Ip"
)
type ResponseRequest struct { type ResponseRequest struct {
UUID string UUID string
Tx corazatypes.Transaction Tx corazatypes.Transaction
@ -77,16 +84,19 @@ func NewParsedRequestFromRequest(r *http.Request) (ParsedRequest, error) {
} }
// the real source of the request is set in 'x-client-ip' // the real source of the request is set in 'x-client-ip'
clientIP := r.Header.Get("X-Client-Ip") clientIP := r.Header.Get(IPHeaderName)
// the real target Host of the request is set in 'x-client-host' // the real target Host of the request is set in 'x-client-host'
clientHost := r.Header.Get("X-Client-Host") clientHost := r.Header.Get(HostHeaderName)
// the real URI of the request is set in 'x-client-uri' // the real URI of the request is set in 'x-client-uri'
clientURI := r.Header.Get("X-Client-Uri") clientURI := r.Header.Get(URIHeaderName)
// the real VERB of the request is set in 'x-client-uri'
clientMethod := r.Header.Get(VerbHeaderName)
// delete those headers before coraza process the request // delete those headers before coraza process the request
delete(r.Header, "x-client-ip") delete(r.Header, IPHeaderName)
delete(r.Header, "x-client-host") delete(r.Header, HostHeaderName)
delete(r.Header, "x-client-uri") delete(r.Header, URIHeaderName)
delete(r.Header, VerbHeaderName)
return ParsedRequest{ return ParsedRequest{
RemoteAddr: r.RemoteAddr, RemoteAddr: r.RemoteAddr,
@ -94,10 +104,10 @@ func NewParsedRequestFromRequest(r *http.Request) (ParsedRequest, error) {
ClientHost: clientHost, ClientHost: clientHost,
ClientIP: clientIP, ClientIP: clientIP,
URI: clientURI, URI: clientURI,
Method: clientMethod,
Host: r.Host, Host: r.Host,
Headers: r.Header, Headers: r.Header,
URL: r.URL, URL: r.URL,
Method: r.Method,
Proto: r.Proto, Proto: r.Proto,
Body: body, Body: body,
TransferEncoding: r.TransferEncoding, TransferEncoding: r.TransferEncoding,