about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNguyễn Gia Phong <cnx@loang.net>2025-07-01 03:39:22 +0900
committerNguyễn Gia Phong <cnx@loang.net>2025-07-01 03:39:22 +0900
commit7d4b6d742dd412befc3a5cbfdc7c1e125f80c568 (patch)
treee5059ecae90849119cb50180fb9b4e4cd976c9f3
parenteb568a7a09cc35dde7b0d2a0828523ec724cddae (diff)
downloadscadere-7d4b6d742dd412befc3a5cbfdc7c1e125f80c568.tar.gz
Omit Atom from Content-Type for browser compat 0.2.2
-rw-r--r--src/scadere/__init__.py2
-rw-r--r--src/scadere/listen.py11
-rw-r--r--tst/test_listen.py2
3 files changed, 11 insertions, 4 deletions
diff --git a/src/scadere/__init__.py b/src/scadere/__init__.py
index 22aa273..baf79cf 100644
--- a/src/scadere/__init__.py
+++ b/src/scadere/__init__.py
@@ -8,7 +8,7 @@ from importlib.resources import files
 
 __all__ = ['__version__', 'GNUHelpFormatter', 'NetLoc',
            'atom2xhtml', 'format_epilog', 'format_version']
-__version__ = '0.2.1'
+__version__ = '0.2.2'
 
 EXAMPLE_PREFIX = ' ' * 2
 # help2man's implementation detail
diff --git a/src/scadere/listen.py b/src/scadere/listen.py
index a435bdc..3cb6bb7 100644
--- a/src/scadere/listen.py
+++ b/src/scadere/listen.py
@@ -227,7 +227,7 @@ def set_http_time_locale():
     setlocale(LC_TIME, 'C')
 
 
-def write_xml(writer, http_version, application, func, *args, mtime=None):
+def write_xml(writer, http_version, subtype, func, *args, mtime=None):
     """Write given document as XML."""
     try:
         content = func(*args)
@@ -236,7 +236,14 @@ def write_xml(writer, http_version, application, func, *args, mtime=None):
         raise
     else:
         write_status(writer, http_version, HTTPStatus.OK)
-        write_content_type(writer, f'application/{application}+xml')
+        if subtype == 'atom':
+            # Firefox would try to download an application/atom+xml
+            # and Chromium would display its source code
+            # instead of applying the XSLT stylesheet
+            # and rendering the resulting hypertext.
+            write_content_type(writer, 'application/xml')
+        else:
+            write_content_type(writer, f'application/{subtype}+xml')
         writer.write(f'Content-Length: {len(content)}\r\n'.encode())
         if mtime is None:
             writer.write(b'Cache-Control: public,'
diff --git a/tst/test_listen.py b/tst/test_listen.py
index f0557d4..85c13f9 100644
--- a/tst/test_listen.py
+++ b/tst/test_listen.py
@@ -197,7 +197,7 @@ def equal_xml(a, b):
 
 async def check_feed(socket, base_url):
     """Check the Atom feed, its stylesheet, and entry pages."""
-    feed = await fetch_xml(socket, base_url, 'application/atom+xml')
+    feed = await fetch_xml(socket, base_url, 'application/xml')
     await check_atom2xhtml(socket, f'{base_url}{__version__}.xslt')
     for entry in feed.findall('entry', ATOM_NAMESPACES):
         link = entry.find('link', ATOM_NAMESPACES).attrib