17
17
from pyld .jsonld import (JsonLdError , parse_link_header , prepend_base , LINK_HEADER_REL )
18
18
19
19
20
- def requests_document_loader (secure = False , max_link_follows = 2 , ** kwargs ):
20
+ def requests_document_loader (secure = False , ** kwargs ):
21
21
"""
22
22
Create a Requests document loader.
23
23
Can be used to setup extra Requests args such as verify, cert, timeout,
24
24
or others.
25
25
:param secure: require all requests to use HTTPS (default: False).
26
- :param max_link_follows: Maximum number of alternate link follows allowed.
27
26
:param **kwargs: extra keyword args for Requests get() call.
28
27
:return: the RemoteDocument loader function.
29
28
"""
30
29
import requests
31
30
32
- def loader (url , options = {}, link_follow_count = 0 ):
31
+ def loader (url , options = {}):
33
32
"""
34
33
Retrieves JSON-LD at the given URL.
35
34
:param url: the URL to retrieve.
@@ -69,8 +68,6 @@ def loader(url, options={}, link_follow_count=0):
69
68
'documentUrl' : response .url ,
70
69
'document' : None
71
70
}
72
- # Try loading the JSON if the content_type matches
73
- # A failure here means the response body is not valid json
74
71
if re .match (r'^application\/(\w*\+)?json$' , content_type ):
75
72
doc ['document' ] = response .json ()
76
73
# if content_type in headers['Accept']:
@@ -97,9 +94,7 @@ def loader(url, options={}, link_follow_count=0):
97
94
not re .match (r'^application\/(\w*\+)?json$' , content_type )):
98
95
doc ['contentType' ] = 'application/ld+json'
99
96
doc ['documentUrl' ] = prepend_base (url , linked_alternate ['target' ])
100
- if link_follow_count >= max_link_follows :
101
- raise requests .TooManyRedirects (f"Exceeded maximum link header redirects ({ max_link_follows } )" )
102
- return loader (doc ['documentUrl' ], options = options , link_follow_count = link_follow_count + 1 )
97
+ return loader (doc ['documentUrl' ], options = options )
103
98
return doc
104
99
except JsonLdError as e :
105
100
raise e
0 commit comments