mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-03-16 22:10:26 +00:00
Elevate redirection to a warning tagged http-redirected
Include the HTTP status code and reason in the message.
This commit is contained in:
parent
f7446043ff
commit
beaf9399f8
7 changed files with 17 additions and 5 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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**
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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."),
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue