mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-03-24 01:40:23 +00:00
Test all http response codes.
This commit is contained in:
parent
5527204623
commit
e91c2edf7e
2 changed files with 44 additions and 2 deletions
|
|
@ -82,19 +82,37 @@ class NoQueryHttpRequestHandler (StoppableHttpRequestHandler):
|
|||
if i != -1:
|
||||
self.path = self.path[:i]
|
||||
|
||||
def get_status(self):
|
||||
dummy, status = self.path.rsplit('/', 1)
|
||||
status = int(status)
|
||||
if status in self.responses:
|
||||
return status
|
||||
return 500
|
||||
|
||||
def do_GET (self):
|
||||
"""
|
||||
Removes query part of GET request.
|
||||
"""
|
||||
self.remove_path_query()
|
||||
super(NoQueryHttpRequestHandler, self).do_GET()
|
||||
if "status/" in self.path:
|
||||
status = self.get_status()
|
||||
self.send_response(status)
|
||||
self.end_headers()
|
||||
if status >= 200 and status not in (204, 304):
|
||||
self.wfile.write("testcontent")
|
||||
else:
|
||||
super(NoQueryHttpRequestHandler, self).do_GET()
|
||||
|
||||
def do_HEAD (self):
|
||||
"""
|
||||
Removes query part of HEAD request.
|
||||
"""
|
||||
self.remove_path_query()
|
||||
super(NoQueryHttpRequestHandler, self).do_HEAD()
|
||||
if "status/" in self.path:
|
||||
self.send_response(self.get_status())
|
||||
self.end_headers()
|
||||
else:
|
||||
super(NoQueryHttpRequestHandler, self).do_HEAD()
|
||||
|
||||
def list_directory(self, path):
|
||||
"""Helper to produce a directory listing (absent index.html).
|
||||
|
|
|
|||
|
|
@ -35,3 +35,27 @@ class TestHttp (HttpServerTest):
|
|||
self.file_test("http.xhtml", confargs=confargs)
|
||||
self.file_test("http_file.html", confargs=confargs)
|
||||
|
||||
def test_status(self):
|
||||
for status in sorted(self.handler.responses.keys()):
|
||||
self._test_status(status)
|
||||
|
||||
def _test_status(self, status):
|
||||
url = u"http://localhost:%d/status/%d" % (self.port, status)
|
||||
resultlines = [
|
||||
u"url %s" % url,
|
||||
u"cache key %s" % url,
|
||||
u"real url %s" % url,
|
||||
]
|
||||
if status in (204,):
|
||||
resultlines.append(u"warning No Content")
|
||||
elif status == 401:
|
||||
resultlines.append(u"warning Unauthorized access without HTTP authentication.")
|
||||
elif status in (301, 302):
|
||||
resultlines.append(u"info Redirected to `%s'." % url)
|
||||
if (status != 101 and status < 200) or status >= 400 or status in (301, 302, 305):
|
||||
result = u"error"
|
||||
else:
|
||||
result = u"valid"
|
||||
resultlines.append(result)
|
||||
self.direct(url, resultlines, recursionlevel=0)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue