Skip to content

Commit

Permalink
tests: linkcheck builder: update test webserver handlers from HTTP/1.…
Browse files Browse the repository at this point in the history
…0 protocol (default) to HTTP/1.1
  • Loading branch information
jayaddison committed Apr 18, 2023
1 parent ad12d25 commit 7162671
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions tests/test_build_linkcheck.py
Expand Up @@ -27,6 +27,8 @@


class DefaultsHandler(http.server.BaseHTTPRequestHandler):
protocol_version = "HTTP/1.1"

def do_HEAD(self):
if self.path[1:].rstrip() == "":
self.send_response(200, "OK")
Expand All @@ -39,12 +41,22 @@ def do_HEAD(self):
self.end_headers()

def do_GET(self):
self.do_HEAD()
if self.path[1:].rstrip() == "":
self.wfile.write(b"ok\n\n")
content = b"ok\n\n"
elif self.path[1:].rstrip() == "anchor.html":
doc = '<!DOCTYPE html><html><body><a id="found"></a></body></html>'
self.wfile.write(doc.encode('utf-8'))
content = doc.encode('utf-8')
else:
content = b""

if content:
self.send_response(200, "OK")
self.send_header("Content-Length", str(len(content)))
self.end_headers()
self.wfile.write(content)
else:
self.send_response(404, "Not Found")
self.end_headers()


@pytest.mark.sphinx('linkcheck', testroot='linkcheck', freshenv=True)
Expand Down Expand Up @@ -181,6 +193,8 @@ def test_anchors_ignored(app):
@pytest.mark.sphinx('linkcheck', testroot='linkcheck-localserver-anchor', freshenv=True)
def test_raises_for_invalid_status(app):
class InternalServerErrorHandler(http.server.BaseHTTPRequestHandler):
protocol_version = "HTTP/1.1"

def do_GET(self):
self.send_error(500, "Internal Server Error")

Expand All @@ -196,6 +210,8 @@ def do_GET(self):

def capture_headers_handler(records):
class HeadersDumperHandler(http.server.BaseHTTPRequestHandler):
protocol_version = "HTTP/1.1"

def do_HEAD(self):
self.do_GET()

Expand Down Expand Up @@ -291,6 +307,8 @@ def test_linkcheck_request_headers_default(app):

def make_redirect_handler(*, support_head):
class RedirectOnceHandler(http.server.BaseHTTPRequestHandler):
protocol_version = "HTTP/1.1"

def do_HEAD(self):
if support_head:
self.do_GET()
Expand Down Expand Up @@ -381,13 +399,17 @@ def test_linkcheck_allowed_redirects(app, warning):


class OKHandler(http.server.BaseHTTPRequestHandler):
protocol_version = "HTTP/1.1"

def do_HEAD(self):
self.send_response(200, "OK")
self.end_headers()

def do_GET(self):
self.do_HEAD()
self.wfile.write(b"ok\n")
content = b"ok\n"
self.send_header("Content-Length", str(len(content)))
self.wfile.write(content)


@pytest.mark.sphinx('linkcheck', testroot='linkcheck-localserver-https', freshenv=True)
Expand Down Expand Up @@ -492,6 +514,8 @@ def test_connect_to_selfsigned_nonexistent_cert_file(app):


class InfiniteRedirectOnHeadHandler(http.server.BaseHTTPRequestHandler):
protocol_version = "HTTP/1.1"

def do_HEAD(self):
self.send_response(302, "Found")
self.send_header("Location", "http://localhost:7777/")
Expand All @@ -500,7 +524,9 @@ def do_HEAD(self):
def do_GET(self):
self.send_response(200, "OK")
self.end_headers()
self.wfile.write(b"ok\n")
content = b"ok\n"
self.send_header("Content-Length", str(len(content)))
self.wfile.write(content)


@pytest.mark.sphinx('linkcheck', testroot='linkcheck-localserver', freshenv=True)
Expand All @@ -526,6 +552,8 @@ def test_TooManyRedirects_on_HEAD(app, monkeypatch):

def make_retry_after_handler(responses):
class RetryAfterHandler(http.server.BaseHTTPRequestHandler):
protocol_version = "HTTP/1.1"

def do_HEAD(self):
status, retry_after = responses.pop(0)
self.send_response(status)
Expand Down Expand Up @@ -677,6 +705,8 @@ def test_limit_rate_bails_out_after_waiting_max_time(app):


class ConnectionResetHandler(http.server.BaseHTTPRequestHandler):
protocol_version = "HTTP/1.1"

def do_HEAD(self):
self.connection.close()

Expand Down

0 comments on commit 7162671

Please sign in to comment.