forked from GithubBackups/healthchecks
Adding Content-Type header to Webhook integrations to work correctly with
services like https://ifttt.com/maker_webhooks which require a specific content type, like application/json.
This commit is contained in:
parent
f2a2241b6b
commit
0ea5927b6a
@ -321,6 +321,12 @@ class Channel(models.Model):
|
||||
parts = self.value.split("\n")
|
||||
return parts[2] if len(parts) > 2 else ""
|
||||
|
||||
@property
|
||||
def content_type(self):
|
||||
assert self.kind == "webhook"
|
||||
parts = self.value.split("\n")
|
||||
return parts[3] if len(parts) > 3 else ""
|
||||
|
||||
@property
|
||||
def slack_team(self):
|
||||
assert self.kind == "slack"
|
||||
|
@ -164,8 +164,11 @@ class Webhook(HttpTransport):
|
||||
|
||||
url = self.prepare(url, check, urlencode=True)
|
||||
if self.channel.post_data:
|
||||
headers = {}
|
||||
if self.channel.content_type:
|
||||
headers["Content-Type"] = self.channel.content_type
|
||||
payload = self.prepare(self.channel.post_data, check)
|
||||
return self.post(url, data=payload.encode("utf-8"))
|
||||
return self.post(url, data=payload.encode("utf-8"), headers=headers)
|
||||
else:
|
||||
return self.get(url)
|
||||
|
||||
@ -230,7 +233,7 @@ class Pushbullet(HttpTransport):
|
||||
url = "https://api.pushbullet.com/v2/pushes"
|
||||
headers = {
|
||||
"Access-Token": self.channel.value,
|
||||
"Conent-Type": "application/json"
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
payload = {
|
||||
"type": "note",
|
||||
|
@ -65,9 +65,11 @@ class AddWebhookForm(forms.Form):
|
||||
|
||||
post_data = forms.CharField(max_length=1000, required=False)
|
||||
|
||||
content_type = forms.CharField(max_length=1000, required=False)
|
||||
|
||||
def get_value(self):
|
||||
d = self.cleaned_data
|
||||
return "\n".join((d["value_down"], d["value_up"], d["post_data"]))
|
||||
return "\n".join((d["value_down"], d["value_up"], d["post_data"], d["content_type"]))
|
||||
|
||||
|
||||
phone_validator = RegexValidator(regex='^\+\d{5,15}$',
|
||||
|
@ -80,6 +80,12 @@
|
||||
<td>{{ ch.post_data }}</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% if ch.content_type %}
|
||||
<tr>
|
||||
<td class="preposition">type </td>
|
||||
<td>{{ ch.content_type }}</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
</table>
|
||||
{% elif ch.kind == "pushbullet" %}
|
||||
<span class="preposition">API key</span>
|
||||
|
@ -105,6 +105,22 @@
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group {{ form.content_type.css_classes }}">
|
||||
<label class="col-sm-2 control-label">Content-Type</label>
|
||||
<div class="col-sm-10">
|
||||
<input
|
||||
type="text"
|
||||
class="form-control"
|
||||
name="content_type"
|
||||
placeholder='application/json'
|
||||
value="{{ form.content_type.value|default:"" }}">
|
||||
{% if form.content_type.errors %}
|
||||
<div class="help-block">
|
||||
{{ form.content_type.errors|join:"" }}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-2 col-sm-10">
|
||||
<button type="submit" class="btn btn-primary">Save Integration</button>
|
||||
|
Loading…
x
Reference in New Issue
Block a user