-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
linkcheck: support ignored-URIs for redirects #13127
base: master
Are you sure you want to change the base?
linkcheck: support ignored-URIs for redirects #13127
Conversation
sphinx/util/requests.py
Outdated
# do not follow redirections that match ignored URI patterns | ||
if resp.is_redirect: | ||
location = resp.headers['location'] | ||
dest = urljoin(resp.url, location) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd draw attention to this line in particular as possibly-dubious.
Servers often respond with relative Location
redirects; but I think we want to match against more-fully-qualified URI paths.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me.
[skip ci]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking great! Thanks for making this update :)
'uri': f'http://{address}/', | ||
'info': f'ignored redirect: http://{address}/redirected', | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be worth adding a test verifying that when the response Location is an absolute URL going to a different server (so it overrides the urljoin base
entirely), it is indeed excluded.
I’m wondering if the change should be considered breaking? An intermediary redirect might match a pattern from |
Thanks @francoisfreitag for the code review! I agree with adding test coverage for a cross-domain redirect case, and I'll do that soon. I'm less sure about whether we should consider it a breaking change - so far we haven't stated anything about the handling of |
Feature or Bugfix
Purpose
linkcheck
client to URLs that the operator has configured as ignored using thelinkcheck_ignore
config setting. This changeset handles those redirections by returning anignore
result immediately, without following the redirect.Detail
requests.Session.get_redirect_target
method so that we can raise a (Sphinx-internal) exception if we encounter a redirect to a configured ignore-URL.Relates
linkcheck_ignore
in link redirection #11233.