Add timeout for webhooks
This commit is contained in:
@@ -34,6 +34,7 @@ class Webhook(RPCHandler):
|
|||||||
self._format = self._config['webhook'].get('format', 'form')
|
self._format = self._config['webhook'].get('format', 'form')
|
||||||
self._retries = self._config['webhook'].get('retries', 0)
|
self._retries = self._config['webhook'].get('retries', 0)
|
||||||
self._retry_delay = self._config['webhook'].get('retry_delay', 0.1)
|
self._retry_delay = self._config['webhook'].get('retry_delay', 0.1)
|
||||||
|
self._timeout = self._config['webhook'].get('timeout', 10)
|
||||||
|
|
||||||
def cleanup(self) -> None:
|
def cleanup(self) -> None:
|
||||||
"""
|
"""
|
||||||
@@ -107,12 +108,13 @@ class Webhook(RPCHandler):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
if self._format == 'form':
|
if self._format == 'form':
|
||||||
response = post(self._url, data=payload)
|
response = post(self._url, data=payload, timeout=self._timeout)
|
||||||
elif self._format == 'json':
|
elif self._format == 'json':
|
||||||
response = post(self._url, json=payload)
|
response = post(self._url, json=payload, timeout=self._timeout)
|
||||||
elif self._format == 'raw':
|
elif self._format == 'raw':
|
||||||
response = post(self._url, data=payload['data'],
|
response = post(self._url, data=payload['data'],
|
||||||
headers={'Content-Type': 'text/plain'})
|
headers={'Content-Type': 'text/plain'},
|
||||||
|
timeout=self._timeout)
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError(f'Unknown format: {self._format}')
|
raise NotImplementedError(f'Unknown format: {self._format}')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user