diff --git a/changedetectionio/fetch_site_status.py b/changedetectionio/fetch_site_status.py index 6c3dbec8..1b1a4827 100644 --- a/changedetectionio/fetch_site_status.py +++ b/changedetectionio/fetch_site_status.py @@ -4,7 +4,8 @@ import os import re import time import urllib3 - +import requests +import simplejson from changedetectionio import content_fetcher, html_tools urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) @@ -67,6 +68,18 @@ class perform_site_check(): # Tweak the base config with the per-watch ones request_headers = self.datastore.data['settings']['headers'].copy() + + if self.datastore.get_val(uuid, 'external_header_server') is not None: + try: + resp = requests.get(self.datastore.get_val(uuid, 'external_header_server')) + if resp.status_code != 200: + raise Exception("External header server returned non-200 response. Please check the URL for the server") + + request_headers.update(resp.json()) + + except simplejson.errors.JSONDecodeError: + raise Exception("Failed to decode JSON response from external header server") + request_headers.update(extra_headers) # https://github.com/psf/requests/issues/4525 diff --git a/changedetectionio/forms.py b/changedetectionio/forms.py index 4ad1b1a7..96ac0e68 100644 --- a/changedetectionio/forms.py +++ b/changedetectionio/forms.py @@ -336,6 +336,7 @@ class watchForm(commonSettingsForm): title = StringField('Title', default='') ignore_text = StringListField('Ignore text', [ValidateListRegex()]) + external_header_server = fields.URLField('External Header Server', validators=[validateURL()]) headers = StringDictKeyValue('Request headers') body = TextAreaField('Request body', [validators.Optional()]) method = SelectField('Request method', choices=valid_method, default=default_method) diff --git a/changedetectionio/model/Watch.py b/changedetectionio/model/Watch.py index acfd9117..9e436b79 100644 --- a/changedetectionio/model/Watch.py +++ b/changedetectionio/model/Watch.py @@ -25,6 +25,7 @@ class model(dict): 'previous_md5': False, 'uuid': str(uuid_builder.uuid4()), 'headers': {}, # Extra headers to send + 'external_header_server': None, # URL to a server that will return headers 'body': None, 'method': 'GET', #'history': {}, # Dict of timestamp and output stripped filename diff --git a/changedetectionio/templates/edit.html b/changedetectionio/templates/edit.html index b13afe46..0012adbb 100644 --- a/changedetectionio/templates/edit.html +++ b/changedetectionio/templates/edit.html @@ -109,6 +109,12 @@