Skip to content

Commit dd0f728

Browse files
authored
Support trigger content type (#26)
1 parent 8d63448 commit dd0f728

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

engine/actions/trigger/rule.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ var (
55
)
66

77
type rule struct {
8-
Endpoint string `mapstructure:"endpoint"`
9-
Method string `mapstructure:"method"`
10-
Headers map[string]string `mapstructure:"headers"`
11-
Body string `mapstructure:"body"`
8+
Endpoint string `mapstructure:"endpoint"`
9+
Method string `mapstructure:"method"`
10+
Headers map[string]string `mapstructure:"headers"`
11+
Body string `mapstructure:"body"`
12+
ContentType string `mapstructure:"content-type"`
1213
}
1314

1415
func (r *rule) Defaults() {
@@ -22,4 +23,7 @@ func (r *rule) Defaults() {
2223
if !allowedMethod {
2324
r.Method = "POST"
2425
}
26+
if r.ContentType == "" {
27+
r.ContentType = "application/json"
28+
}
2529
}

engine/actions/trigger/trigger.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (a *action) prepareRequest(meta types.Data) *http.Request {
6868
func (a *action) setRequestHeaders(request *http.Request) {
6969
request.Header.Set("User-Agent", "Rivi-Agent/1.0")
7070
request.Header.Set("X-Rivi-Event", "trigger")
71-
request.Header.Set("Content-Type", "application/json")
71+
request.Header.Set("Content-Type", a.rule.ContentType)
7272
for name, value := range a.rule.Headers {
7373
lowerName := strings.ToLower(name)
7474
if !strings.HasPrefix(lowerName, "x-") || strings.HasPrefix(lowerName, "x-rivi") {

engine/actions/trigger/trigger.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ None
3232
- `endpoint` (required) - the target endpoint
3333
- `method` (optional) - HTTP method (`GET` or `POST`) (default: **POST**)
3434
- `headers` (optional) - key-values to add to request. Must start with `X-` otherwise will not be included
35+
- `body` (optional) - Template for posted data
36+
- `content-type` (optional) - Set `Content-Type` header (default: **`application/json`**)
3537

3638
## Example
3739
```yaml

0 commit comments

Comments
 (0)