diff --git a/doc/changelog.txt b/doc/changelog.txt index 6a9c3466..8eb4ec63 100644 --- a/doc/changelog.txt +++ b/doc/changelog.txt @@ -2,6 +2,7 @@ Changes: - Minimum Python version required is 3.8 +- HTTP redirect causes a warning, http-redirected 10.2.1 (released 05.12.2022) diff --git a/doc/src/man/linkcheckerrc.rst b/doc/src/man/linkcheckerrc.rst index 63c03e12..6b2986d2 100644 --- a/doc/src/man/linkcheckerrc.rst +++ b/doc/src/man/linkcheckerrc.rst @@ -584,6 +584,8 @@ file entry: The URL had no content. **http-rate-limited** Too many HTTP requests. +**http-redirected** + Redirected to a different URL. **mail-no-mx-host** The mail MX host could not be found. **nntp-no-newsgroup** diff --git a/doc/upgrading.txt b/doc/upgrading.txt index 49d82630..41fb3bc7 100644 --- a/doc/upgrading.txt +++ b/doc/upgrading.txt @@ -5,6 +5,9 @@ Migrating from 10.2 to 10.x --------------------------- Python 3.8 or newer is required. +An HTTP redirect now causes a warning. Set ignorewarnings=http-redirected in +linkcheckerrc for the previous behaviour. + Migrating from 10.1 to 10.2 --------------------------- Python 3.7 or newer is required. diff --git a/linkcheck/checker/const.py b/linkcheck/checker/const.py index ee55d04e..e18dea45 100644 --- a/linkcheck/checker/const.py +++ b/linkcheck/checker/const.py @@ -93,6 +93,7 @@ WARN_FTP_MISSING_SLASH = "ftp-missing-slash" WARN_HTTP_EMPTY_CONTENT = "http-empty-content" WARN_HTTP_COOKIE_STORE_ERROR = "http-cookie-store-error" WARN_HTTP_RATE_LIMITED = "http-rate-limited" +WARN_HTTP_REDIRECTED = "http-redirected" WARN_MAIL_NO_MX_HOST = "mail-no-mx-host" WARN_NNTP_NO_SERVER = "nntp-no-server" WARN_NNTP_NO_NEWSGROUP = "nntp-no-newsgroup" @@ -117,6 +118,7 @@ Warnings = { WARN_HTTP_EMPTY_CONTENT: _("The URL had no content."), WARN_HTTP_COOKIE_STORE_ERROR: _("An error occurred while storing a cookie."), WARN_HTTP_RATE_LIMITED: _("The URL request was rate limited."), + WARN_HTTP_REDIRECTED: _("Redirected to a different URL."), WARN_MAIL_NO_MX_HOST: _("The mail MX host could not be found."), WARN_NNTP_NO_SERVER: _("No NNTP server was found."), WARN_NNTP_NO_NEWSGROUP: _("The NNTP newsgroup could not be found."), diff --git a/linkcheck/checker/httpurl.py b/linkcheck/checker/httpurl.py index eb55b719..6498bd09 100644 --- a/linkcheck/checker/httpurl.py +++ b/linkcheck/checker/httpurl.py @@ -44,7 +44,7 @@ from .. import ( from . import internpaturl # import warnings -from .const import WARN_HTTP_EMPTY_CONTENT, WARN_HTTP_RATE_LIMITED +from .const import WARN_HTTP_EMPTY_CONTENT, WARN_HTTP_RATE_LIMITED, WARN_HTTP_REDIRECTED from requests.sessions import REDIRECT_STATI HTTP_SCHEMAS = ('http://', 'https://') @@ -279,7 +279,11 @@ class HttpUrl(internpaturl.InternPatternUrl): log.debug(LOG_CHECK, "Redirected to %r", newurl) self.aliases.append(newurl) # XXX on redirect errors this is not printed - self.add_info(_("Redirected to `%(url)s'.") % {'url': newurl}) + self.add_warning( + _("Redirected to `%(url)s' status: %(code)d %(reason)s.") + % {'url': newurl, 'code': self.url_connection.status_code, + 'reason': self.url_connection.reason}, + tag=WARN_HTTP_REDIRECTED) # Reset extern and recalculate self.extern = None self.set_extern(newurl) diff --git a/tests/checker/data/redir.html.result b/tests/checker/data/redir.html.result index 02a5a93c..2961651b 100644 --- a/tests/checker/data/redir.html.result +++ b/tests/checker/data/redir.html.result @@ -7,5 +7,5 @@ url redirect_newhost.html cache key http://localhost:%(port)d/%(datadir)s/redirect_newhost.html real url http://www.example.com/ name redirect to new host -info Redirected to `http://www.example.com/'. +warning Redirected to `http://www.example.com/' status: 302 Found. valid diff --git a/tests/checker/test_http_redirect.py b/tests/checker/test_http_redirect.py index 1d18dc39..672309f7 100644 --- a/tests/checker/test_http_redirect.py +++ b/tests/checker/test_http_redirect.py @@ -43,7 +43,7 @@ class TestHttpRedirect(HttpServerTest): "url %s" % url, "cache key %s" % nurl, "real url %s" % rurl, - "info Redirected to `%s'." % rurl, + "warning Redirected to `%s' status: 302 Found." % rurl, "error", ] self.direct(url, resultlines, recursionlevel=0) @@ -56,7 +56,7 @@ class TestHttpRedirect(HttpServerTest): "url %s" % url, "cache key %s" % nurl, "real url %s" % rurl, - "info Redirected to `%s'." % rurl, + "warning Redirected to `%s' status: 302 Found." % rurl, "valid", ] self.direct(url, resultlines, recursionlevel=99)