mirror of
https://github.com/adnanh/webhook.git
synced 2025-06-01 18:22:27 +00:00
Add option to send raw request body to command
The existing `entire-payload` option sends a JSON representation of the parsed request body. Add a new `raw-request-body` source to send the raw request body. Fixes #439
This commit is contained in:
parent
3e18a060ae
commit
62f9c01cab
4 changed files with 50 additions and 9 deletions
|
@ -31,15 +31,16 @@ import (
|
||||||
|
|
||||||
// Constants used to specify the parameter source
|
// Constants used to specify the parameter source
|
||||||
const (
|
const (
|
||||||
SourceHeader string = "header"
|
SourceHeader string = "header"
|
||||||
SourceQuery string = "url"
|
SourceQuery string = "url"
|
||||||
SourceQueryAlias string = "query"
|
SourceQueryAlias string = "query"
|
||||||
SourcePayload string = "payload"
|
SourcePayload string = "payload"
|
||||||
SourceRequest string = "request"
|
SourceRawRequestBody string = "raw-request-body"
|
||||||
SourceString string = "string"
|
SourceRequest string = "request"
|
||||||
SourceEntirePayload string = "entire-payload"
|
SourceString string = "string"
|
||||||
SourceEntireQuery string = "entire-query"
|
SourceEntirePayload string = "entire-payload"
|
||||||
SourceEntireHeaders string = "entire-headers"
|
SourceEntireQuery string = "entire-query"
|
||||||
|
SourceEntireHeaders string = "entire-headers"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -449,6 +450,9 @@ func (ha *Argument) Get(r *Request) (string, error) {
|
||||||
case SourceString:
|
case SourceString:
|
||||||
return ha.Name, nil
|
return ha.Name, nil
|
||||||
|
|
||||||
|
case SourceRawRequestBody:
|
||||||
|
return string(r.Body), nil
|
||||||
|
|
||||||
case SourceRequest:
|
case SourceRequest:
|
||||||
if r == nil || r.RawRequest == nil {
|
if r == nil || r.RawRequest == nil {
|
||||||
return "", errors.New("request is nil")
|
return "", errors.New("request is nil")
|
||||||
|
|
|
@ -168,6 +168,17 @@
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "txt-raw",
|
||||||
|
"execute-command": "{{ .Hookecho }}",
|
||||||
|
"command-working-directory": "/",
|
||||||
|
"include-command-output-in-response": true,
|
||||||
|
"pass-arguments-to-command": [
|
||||||
|
{
|
||||||
|
"source": "raw-request-body"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "sendgrid",
|
"id": "sendgrid",
|
||||||
"execute-command": "{{ .Hookecho }}",
|
"execute-command": "{{ .Hookecho }}",
|
||||||
|
|
|
@ -97,6 +97,13 @@
|
||||||
name: "app.messages.message.#text"
|
name: "app.messages.message.#text"
|
||||||
value: "Hello!!"
|
value: "Hello!!"
|
||||||
|
|
||||||
|
- id: txt-raw
|
||||||
|
execute-command: '{{ .Hookecho }}'
|
||||||
|
command-working-directory: /
|
||||||
|
include-command-output-in-response: true
|
||||||
|
pass-arguments-to-command:
|
||||||
|
- source: raw-request-body
|
||||||
|
|
||||||
- id: sendgrid
|
- id: sendgrid
|
||||||
execute-command: '{{ .Hookecho }}'
|
execute-command: '{{ .Hookecho }}'
|
||||||
command-working-directory: /
|
command-working-directory: /
|
||||||
|
|
|
@ -572,6 +572,25 @@ env: HOOK_head_commit.timestamp=2013-03-12T08:14:29-07:00
|
||||||
`success`,
|
`success`,
|
||||||
``,
|
``,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"txt-raw",
|
||||||
|
"txt-raw",
|
||||||
|
nil,
|
||||||
|
"POST",
|
||||||
|
map[string]string{"Content-Type": "text/plain"},
|
||||||
|
"text/plain",
|
||||||
|
`# FOO
|
||||||
|
|
||||||
|
blah
|
||||||
|
blah`,
|
||||||
|
false,
|
||||||
|
http.StatusOK,
|
||||||
|
`# FOO
|
||||||
|
|
||||||
|
blah
|
||||||
|
blah`,
|
||||||
|
``,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"payload-json-array",
|
"payload-json-array",
|
||||||
"sendgrid",
|
"sendgrid",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue