Skip to content

Commit

Permalink
pass custom headers to http notifications. (#357)
Browse files Browse the repository at this point in the history
* pass custom headers to http notifications.

* pass custom headers to http notifications.

* add notifiers headers test.
  • Loading branch information
vixns authored and toddpalino committed May 3, 2018
1 parent 7c0b8b1 commit fecab1e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/internal/notifier/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ func (module *HTTPNotifier) Notify(status *protocol.ConsumerGroupStatus, eventID
}
req.Header.Set("Content-Type", "application/json")

for header, value := range viper.GetStringMapString("notifier." + module.name + ".headers") {
req.Header.Set(header, value)
}

resp, err := module.httpClient.Do(req)
if err != nil {
logger.Error("failed to send", zap.Error(err))
Expand Down
9 changes: 9 additions & 0 deletions core/internal/notifier/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func fixtureHTTPNotifier() *HTTPNotifier {
viper.Set("notifier.test.template-open", "template_open")
viper.Set("notifier.test.template-close", "template_close")
viper.Set("notifier.test.send-close", false)
viper.Set("notifier.test.headers", map[string]string{"Token": "testtoken"})

return &module
}
Expand Down Expand Up @@ -91,6 +92,10 @@ func TestHttpNotifier_Notify_Open(t *testing.T) {
assert.Len(t, headers, 1, "Expected to receive exactly one Content-Type header")
assert.Equalf(t, "application/json", headers[0], "Expected Content-Type header to be 'application/json', not '%v'", headers[0])

tokenHeaders, ok := r.Header["Token"]
assert.True(t, ok, "Expected to receive Token header")
assert.Equalf(t, "testtoken", tokenHeaders[0], "Expected Token header to be 'testtoken', not '%v'", tokenHeaders[0])

decoder := json.NewDecoder(r.Body)
var req HTTPRequest
err := decoder.Decode(&req)
Expand Down Expand Up @@ -138,6 +143,10 @@ func TestHttpNotifier_Notify_Close(t *testing.T) {
assert.Len(t, headers, 1, "Expected to receive exactly one Content-Type header")
assert.Equalf(t, "application/json", headers[0], "Expected Content-Type header to be 'application/json', not '%v'", headers[0])

tokenHeaders, ok := r.Header["Token"]
assert.True(t, ok, "Expected to receive Token header")
assert.Equalf(t, "testtoken", tokenHeaders[0], "Expected Token header to be 'testtoken', not '%v'", tokenHeaders[0])

decoder := json.NewDecoder(r.Body)
var req HTTPRequest
err := decoder.Decode(&req)
Expand Down

0 comments on commit fecab1e

Please sign in to comment.