Browse Source

Webhook header values can contain variables.

pull/142/head
Pēteris Caune 7 years ago
parent
commit
4cdc7db035
2 changed files with 24 additions and 1 deletions
  1. +20
    -0
      hc/api/tests/test_notify.py
  2. +4
    -1
      hc/api/transports.py

+ 20
- 0
hc/api/tests/test_notify.py View File

@ -215,6 +215,26 @@ class NotifyTestCase(BaseTestCase):
mock_request.assert_called_with(
"get", "http://foo.com", headers=headers, timeout=5)
@patch("hc.api.transports.requests.request")
def test_webhooks_support_variables_in_headers(self, mock_request):
definition = {
"url_down": "http://foo.com",
"headers": {"X-Message": "$NAME is DOWN"}
}
self._setup_data("webhook", json.dumps(definition))
self.check.name = "Foo"
self.check.save()
self.channel.notify(self.check)
headers = {
"User-Agent": "healthchecks.io",
"X-Message": "Foo is DOWN"
}
mock_request.assert_called_with(
"get", "http://foo.com", headers=headers, timeout=5)
def test_email(self):
self._setup_data("email", "[email protected]")
self.channel.notify(self.check)


+ 4
- 1
hc/api/transports.py View File

@ -166,7 +166,10 @@ class Webhook(HttpTransport):
assert url
url = self.prepare(url, check, urlencode=True)
headers = self.channel.headers
headers = {}
for key, value in self.channel.headers.items():
headers[key] = self.prepare(value, check)
if self.channel.post_data:
payload = self.prepare(self.channel.post_data, check)
return self.post(url, data=payload.encode("utf-8"), headers=headers)


Loading…
Cancel
Save