Skip to content
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

quick fix for Link header handling for json-ld #1125

Closed
wants to merge 4 commits into from
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
14 changes: 14 additions & 0 deletions rdflib/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,20 @@ def __init__(self, system_id=None, format=None):

req = Request(system_id, None, myheaders)
file = urlopen(req)
#Fix for https://github.com/RDFLib/rdflib-jsonld/issues/85
#TODO: Check if Link header is supported for other formats
if format == "json-ld":
# Check for a Link header in response, rfc8288
_link = file.getheader("Link", None)
if not _link is None:
#TODO: Scan for content type in potentially multiple Link headers
# Grab the possibly relative URL
link_url = _link.split(";")[0].strip("<>")
link_url = urljoin(self.url, link_url)
#Reissue the request to the Link URL
req = Request(link_url, None, myheaders)
file = urlopen(req)

# Fix for issue 130 https://github.com/RDFLib/rdflib/issues/130
self.url = file.geturl() # in case redirections took place
self.setPublicId(self.url)
Expand Down