From a6f9cc390cd7273bbd9de8111d9f1de8512e6a4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Van=20Rompay?= Date: Sat, 19 Dec 2020 15:48:13 +0100 Subject: [PATCH] avoid duplicate "header" kwarg Fixes https://github.com/digitalbazaar/pyld/issues/133 If headers were passed during call to `requests_document_loader`, these headers will be forced in call to `requests.get`. --- lib/pyld/documentloader/requests.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/pyld/documentloader/requests.py b/lib/pyld/documentloader/requests.py index 77f42e1d..1cdd8b1d 100644 --- a/lib/pyld/documentloader/requests.py +++ b/lib/pyld/documentloader/requests.py @@ -14,6 +14,9 @@ from pyld.jsonld import (JsonLdError, parse_link_header, LINK_HEADER_REL) +DEFAULT_HEADERS = { + 'Accept': 'application/ld+json, application/json' +} def requests_document_loader(secure=False, **kwargs): """ @@ -55,12 +58,16 @@ def loader(url, options={}): 'the URL\'s scheme is not "https".', 'jsonld.InvalidUrl', {'url': url}, code='loading document failed') - headers = options.get('headers') - if headers is None: - headers = { - 'Accept': 'application/ld+json, application/json' - } - response = requests.get(url, headers=headers, **kwargs) + + headers = {} if 'headers' in kwargs else ({ + 'headers': ( + options.get('headers', None) + or DEFAULT_HEADERS + ) + }) + + response = requests.get(url, **kwargs, **headers) + content_type = response.headers.get('content-type') if not content_type: