mirror of
https://github.com/adnanh/webhook.git
synced 2025-06-01 02:02:28 +00:00
Add request source
Add "request" source with support for "method" and "remote-addr" parameters. Both values are taken from the raw http.Request object. Fixes #312
This commit is contained in:
parent
e513eb4bf4
commit
346c761ef6
6 changed files with 136 additions and 28 deletions
|
@ -35,6 +35,7 @@ const (
|
|||
SourceQuery string = "url"
|
||||
SourceQueryAlias string = "query"
|
||||
SourcePayload string = "payload"
|
||||
SourceRequest string = "request"
|
||||
SourceString string = "string"
|
||||
SourceEntirePayload string = "entire-payload"
|
||||
SourceEntireQuery string = "entire-query"
|
||||
|
@ -438,12 +439,30 @@ func (ha *Argument) Get(r *Request) (string, error) {
|
|||
case SourceHeader:
|
||||
source = &r.Headers
|
||||
key = textproto.CanonicalMIMEHeaderKey(ha.Name)
|
||||
|
||||
case SourceQuery, SourceQueryAlias:
|
||||
source = &r.Query
|
||||
|
||||
case SourcePayload:
|
||||
source = &r.Payload
|
||||
|
||||
case SourceString:
|
||||
return ha.Name, nil
|
||||
|
||||
case SourceRequest:
|
||||
if r == nil || r.RawRequest == nil {
|
||||
return "", errors.New("request is nil")
|
||||
}
|
||||
|
||||
switch ha.Name {
|
||||
case "remote-addr":
|
||||
return r.RawRequest.RemoteAddr, nil
|
||||
case "method":
|
||||
return r.RawRequest.Method, nil
|
||||
default:
|
||||
return "", fmt.Errorf("unsupported request key: %q", ha.Name)
|
||||
}
|
||||
|
||||
case SourceEntirePayload:
|
||||
res, err := json.Marshal(&r.Payload)
|
||||
if err != nil {
|
||||
|
@ -451,6 +470,7 @@ func (ha *Argument) Get(r *Request) (string, error) {
|
|||
}
|
||||
|
||||
return string(res), nil
|
||||
|
||||
case SourceEntireHeaders:
|
||||
res, err := json.Marshal(&r.Headers)
|
||||
if err != nil {
|
||||
|
@ -458,6 +478,7 @@ func (ha *Argument) Get(r *Request) (string, error) {
|
|||
}
|
||||
|
||||
return string(res), nil
|
||||
|
||||
case SourceEntireQuery:
|
||||
res, err := json.Marshal(&r.Query)
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue