From 1f7f1e2bfaf1877f57530b7f4af858e6d86f3ad6 Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Thu, 30 Nov 2023 11:33:36 +0100 Subject: [PATCH 1/2] Fixing support for headers in custom post, posts etc notifications --- changedetectionio/notification.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/changedetectionio/notification.py b/changedetectionio/notification.py index 6c0f53f6..12985814 100644 --- a/changedetectionio/notification.py +++ b/changedetectionio/notification.py @@ -46,6 +46,9 @@ from apprise.decorators import notify @notify(on="puts") def apprise_custom_api_call_wrapper(body, title, notify_type, *args, **kwargs): import requests + from apprise.utils import parse_url as apprise_parse_url + from apprise.URLBase import URLBase + url = kwargs['meta'].get('url') if url.startswith('post'): @@ -68,15 +71,22 @@ def apprise_custom_api_call_wrapper(body, title, notify_type, *args, **kwargs): url = url.replace('delete://', 'http://') url = url.replace('deletes://', 'https://') - # Try to auto-guess if it's JSON headers = {} + # Convert /foobar?+some-header=hello to proper header dictionary + results = apprise_parse_url(url) + if results: + # Add our headers that the user can potentially over-ride if they wish + # to to our returned result set and tidy entries by unquoting them + headers = {URLBase.unquote(x): URLBase.unquote(y) + for x, y in results['qsd+'].items()} + + # Try to auto-guess if it's JSON try: json.loads(body) - headers = {'Content-Type': 'application/json; charset=utf-8'} + headers['Content-Type'] = 'application/json; charset=utf-8' except ValueError as e: pass - r(url, headers=headers, data=body) From b899579ca8c42c254489ede9cc350a651cedb33e Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Thu, 30 Nov 2023 12:15:22 +0100 Subject: [PATCH 2/2] properly handle user/pass auth and clean URL without token --- changedetectionio/notification.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/changedetectionio/notification.py b/changedetectionio/notification.py index 12985814..7f08c1b3 100644 --- a/changedetectionio/notification.py +++ b/changedetectionio/notification.py @@ -72,6 +72,9 @@ def apprise_custom_api_call_wrapper(body, title, notify_type, *args, **kwargs): url = url.replace('deletes://', 'https://') headers = {} + params = {} + auth = None + # Convert /foobar?+some-header=hello to proper header dictionary results = apprise_parse_url(url) if results: @@ -80,6 +83,17 @@ def apprise_custom_api_call_wrapper(body, title, notify_type, *args, **kwargs): headers = {URLBase.unquote(x): URLBase.unquote(y) for x, y in results['qsd+'].items()} + # Add our GET paramters in the event the user wants to pass these along + params = {URLBase.unquote(x): URLBase.unquote(y) + for x, y in results['qsd-'].items()} + + # Determine Authentication + auth = '' + if results.get('user') and results.get('password'): + auth = (URLBase.unquote(results.get('user')), URLBase.unquote(results.get('user'))) + elif results.get('user'): + auth = (URLBase.unquote(results.get('user'))) + # Try to auto-guess if it's JSON try: json.loads(body) @@ -87,7 +101,12 @@ def apprise_custom_api_call_wrapper(body, title, notify_type, *args, **kwargs): except ValueError as e: pass - r(url, headers=headers, data=body) + r(results.get('url'), + headers=headers, + data=body, + params=params, + auth=auth + ) def process_notification(n_object, datastore):