]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-123430: Add dark mode support to pages generated by http.server (#123475)
authorYorik Hansen <github@yorik.dev>
Tue, 3 Sep 2024 06:32:11 +0000 (08:32 +0200)
committerGitHub <noreply@github.com>
Tue, 3 Sep 2024 06:32:11 +0000 (09:32 +0300)
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
Doc/whatsnew/3.14.rst
Lib/http/server.py
Misc/NEWS.d/next/Library/2024-08-29-14-51-36.gh-issue-123430.M7wXl9.rst [new file with mode: 0644]

index 4817c5258052e1168b13cd4b6f7a2e5c39f30123..233d7ce0399cd63294f71dfc736b162de7a8c7ec 100644 (file)
@@ -151,6 +151,14 @@ Added support for converting any objects that have the
 (Contributed by Serhiy Storchaka in :gh:`82017`.)
 
 
+http
+----
+
+Directory lists and error pages generated by the :mod:`http.server`
+module allow the browser to apply its default dark mode.
+(Contributed by Yorik Hansen in :gh:`123430`.)
+
+
 json
 ----
 
index 2d010649e56b518ae91523b3b03f56025fbf15f2..a6f7aecc78763fd9559c540eb9c0d032f20c2e92 100644 (file)
@@ -114,6 +114,11 @@ DEFAULT_ERROR_MESSAGE = """\
 <html lang="en">
     <head>
         <meta charset="utf-8">
+        <style type="text/css">
+            :root {
+                color-scheme: light dark;
+            }
+        </style>
         <title>Error response</title>
     </head>
     <body>
@@ -804,6 +809,7 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
         r.append('<html lang="en">')
         r.append('<head>')
         r.append(f'<meta charset="{enc}">')
+        r.append('<style type="text/css">\n:root {\ncolor-scheme: light dark;\n}\n</style>')
         r.append(f'<title>{title}</title>\n</head>')
         r.append(f'<body>\n<h1>{title}</h1>')
         r.append('<hr>\n<ul>')
diff --git a/Misc/NEWS.d/next/Library/2024-08-29-14-51-36.gh-issue-123430.M7wXl9.rst b/Misc/NEWS.d/next/Library/2024-08-29-14-51-36.gh-issue-123430.M7wXl9.rst
new file mode 100644 (file)
index 0000000..0afdad7
--- /dev/null
@@ -0,0 +1 @@
+Pages generated by the :mod:`http.server` module allow the browser to apply its default dark mode.