Merge pull request #8475 from tk0miya/8131_too_many_redirects

Extend linkchecker GET fallback logic to handle Too Many Redirects
This commit is contained in:
Takeshi KOMIYA 2020-11-23 17:16:51 +09:00 committed by GitHub
commit 0131f776fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 2 deletions

View File

@ -58,6 +58,8 @@ Bugs fixed
information of TypeVars information of TypeVars
* #8419: html search: Do not load ``language_data.js`` in non-search pages * #8419: html search: Do not load ``language_data.js`` in non-search pages
* #8454: graphviz: The layout option for graph and digraph directives don't work * #8454: graphviz: The layout option for graph and digraph directives don't work
* #8131: linkcheck: Use GET when HEAD requests cause Too Many Redirects, to
accommodate infinite redirect loops on HEAD
* #8437: Makefile: ``make clean`` with empty BUILDDIR is dangerous * #8437: Makefile: ``make clean`` with empty BUILDDIR is dangerous
Testing Testing

View File

@ -20,7 +20,7 @@ from urllib.parse import unquote, urlparse
from docutils import nodes from docutils import nodes
from docutils.nodes import Node from docutils.nodes import Node
from requests.exceptions import HTTPError from requests.exceptions import HTTPError, TooManyRedirects
from sphinx.application import Sphinx from sphinx.application import Sphinx
from sphinx.builders import Builder from sphinx.builders import Builder
@ -172,7 +172,7 @@ class CheckExternalLinksBuilder(Builder):
config=self.app.config, auth=auth_info, config=self.app.config, auth=auth_info,
**kwargs) **kwargs)
response.raise_for_status() response.raise_for_status()
except HTTPError: except (HTTPError, TooManyRedirects):
# retry with GET request if that fails, some servers # retry with GET request if that fails, some servers
# don't like HEAD requests. # don't like HEAD requests.
response = requests.get(req_url, stream=True, config=self.app.config, response = requests.get(req_url, stream=True, config=self.app.config,

View File

@ -382,3 +382,31 @@ def test_connect_to_selfsigned_nonexistent_cert_file(app):
"uri": "https://localhost:7777/", "uri": "https://localhost:7777/",
"info": "Could not find a suitable TLS CA certificate bundle, invalid path: does/not/exist", "info": "Could not find a suitable TLS CA certificate bundle, invalid path: does/not/exist",
} }
@pytest.mark.sphinx('linkcheck', testroot='linkcheck-localserver', freshenv=True)
def test_TooManyRedirects_on_HEAD(app):
class InfiniteRedirectOnHeadHandler(http.server.BaseHTTPRequestHandler):
def do_HEAD(self):
self.send_response(302, "Found")
self.send_header("Location", "http://localhost:7777/")
self.end_headers()
def do_GET(self):
self.send_response(200, "OK")
self.end_headers()
self.wfile.write(b"ok\n")
with http_server(InfiniteRedirectOnHeadHandler):
app.builder.build_all()
with open(app.outdir / 'output.json') as fp:
content = json.load(fp)
assert content == {
"code": 0,
"status": "working",
"filename": "index.rst",
"lineno": 1,
"uri": "http://localhost:7777/",
"info": "",
}