Skip to content

avoid duplicate "header" kwarg #144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions lib/pyld/documentloader/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

from pyld.jsonld import (JsonLdError, parse_link_header, LINK_HEADER_REL)

DEFAULT_HEADERS = {
'Accept': 'application/ld+json, application/json'
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I appreciate factoring this out as a global constant.


def requests_document_loader(secure=False, **kwargs):
"""
Expand Down Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is unclear how this PR is changing the behavior. From what I am seeing, even before the PR a user could do

requests_document_loader(…, headers={
    'Foo': 'bar',
})

it should be working on implementation at master. Or am I misunderstanding it?


headers = {} if 'headers' in kwargs else ({
'headers': (
options.get('headers', None)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we're addressing both kwargs['headers'] and options['headers'], where should those be found?

or DEFAULT_HEADERS
)
})

response = requests.get(url, **kwargs, **headers)


content_type = response.headers.get('content-type')
if not content_type:
Expand Down