feat: also add page for /

This commit is contained in:
mxmehl committed 2026-10-22 13:56:15 +02:00
1 parent 7a2d7c6650
commit 186fe7f9ee
3 files changed
+30 -4

No files matched your search

+20 -3
View File
@@ -224,11 +224,28 @@ def handle(env, cfg, update=inwx_update):
return 200, "\n".join(lines)
INDEX_HTML = """<!DOCTYPE html>
<html lang="en-GB">
<head>
<meta charset="utf-8">
<title>Snap DynDNS Server</title>
</head>
<body>
<h1>Snap DynDNS Server</h1>
<p>This is a Dynamic DNS service. It is running with the <a href="https://src.mehl.mx/mxmehl/snap-dyndns-server">Snap DynDNS Server</a> software.</p>
<p>Please contact the site owner for more information on this specific service.</p>
</body>
</html>
"""
class RequestHandler(http.server.BaseHTTPRequestHandler):
timeout = 30 # do not let stalled connections hold a thread forever
def do_GET(self):
url = urllib.parse.urlsplit(self.path)
if url.path in ("/", "/nic", "/nic/"):
return self._reply(200, INDEX_HTML, "text/html")
if url.path != "/nic/update":
return self._reply(404, "not found")
try:
@@ -253,10 +270,10 @@ class RequestHandler(http.server.BaseHTTPRequestHandler):
return self.headers.get(name, "").split(",")[-1].strip()
return self.client_address[0]
def _reply(self, status, body):
data = (body + "\n").encode()
def _reply(self, status, body, content_type="text/plain"):
data = (body if body.endswith("\n") else body + "\n").encode()
self.send_response(status)
self.send_header("Content-Type", "text/plain; charset=utf-8")
self.send_header("Content-Type", f"{content_type}; charset=utf-8")
self.send_header("Content-Length", str(len(data)))
self.send_header("Cache-Control", "no-store")
if status == 401: