Skip to content

Commit

Permalink
linkcheck: Set allow_redirects in requests.head() call
Browse files Browse the repository at this point in the history
Following redirects is the default for other methods.
https://requests.readthedocs.io/en/latest/api/#requests.request

Define the option closer to its use.
  • Loading branch information
francoisfreitag committed Nov 11, 2020
1 parent 53ca608 commit 640cc40
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions sphinx/builders/linkcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@ def init(self) -> None:
self.workers.append(thread)

def check_thread(self) -> None:
kwargs = {
'allow_redirects': True,
} # type: Dict
kwargs = {}
if self.app.config.linkcheck_timeout:
kwargs['timeout'] = self.app.config.linkcheck_timeout

Expand Down Expand Up @@ -171,8 +169,9 @@ def check_uri() -> Tuple[str, str, int]:
try:
# try a HEAD request first, which should be easier on
# the server and the network
response = requests.head(req_url, config=self.app.config,
auth=auth_info, **kwargs)
response = requests.head(req_url, allow_redirects=True,
config=self.app.config, auth=auth_info,
**kwargs)
response.raise_for_status()
except HTTPError:
# retry with GET request if that fails, some servers
Expand Down

0 comments on commit 640cc40

Please sign in to comment.