diff --git a/changes-entries/autoindex-charset-meta.txt b/changes-entries/autoindex-charset-meta.txt
new file mode 100644
index 00000000000..2e20ee80b6e
--- /dev/null
+++ b/changes-entries/autoindex-charset-meta.txt
@@ -0,0 +1,3 @@
+ *) mod_autoindex: Emit the charset given by "IndexOptions Charset=" in a
+ tag of the generated page for HTML 4.01 as well as XHTML, ahead
+ of the page title. PR 69930.
diff --git a/modules/generators/mod_autoindex.c b/modules/generators/mod_autoindex.c
index 37bed118b06..c7994e3105a 100644
--- a/modules/generators/mod_autoindex.c
+++ b/modules/generators/mod_autoindex.c
@@ -178,17 +178,16 @@ static void emit_preamble(request_rec *r, int xhtml, const char *title)
ap_rvputs(r, DOCTYPE_XHTML_1_0T,
"\n"
"
\n", NULL);
- if(d->charset != NULL) {
- ap_rvputs(r, " \n", NULL);
- }
- ap_rvputs(r, " Index of ", title,
- "\n", NULL);
- } else {
- ap_rvputs(r, DOCTYPE_HTML_4_01,
- "\n \n"
- " Index of ", title,
- "\n", NULL);
}
+ else {
+ ap_rvputs(r, DOCTYPE_HTML_4_01, "\n \n", NULL);
+ }
+
+ if (d->charset != NULL && *d->charset) {
+ ap_rvputs(r, " charset, xhtml ? "\" />\n" : "\">\n", NULL);
+ }
+ ap_rvputs(r, " Index of ", title, "\n", NULL);
if (d->style_sheet != NULL) {
ap_rvputs(r, " style_sheet,
diff --git a/test/modules/generators/test_002_autoindex.py b/test/modules/generators/test_002_autoindex.py
index 062f54b0d05..14d6099ddbe 100644
--- a/test/modules/generators/test_002_autoindex.py
+++ b/test/modules/generators/test_002_autoindex.py
@@ -18,6 +18,17 @@ def _class_scope(cls, env):
Options +Indexes
IndexOptions FancyIndexing ScanHTMLTitles
+
+
+ IndexOptions XHTML Charset=ISO-8859-2
+
+
+ IndexOptions Charset=
+
+
+ IndexOptions Charset=ISO-8859-2
+
+
"""),
})
conf.add_vhost(domains=[domain], port=env.http_port,
@@ -33,3 +44,29 @@ def test_generators_002_01_scan_title_bare_amp(self, env):
r = env.curl_get(env.mkurl("http", "autoindex", "/listing/"))
assert r.response["status"] == 200
assert "AT&T" in r.response["body"].decode()
+
+ def test_generators_002_02_charset_meta_html(self, env):
+ """IndexOptions Charset= adds a to the HTML 4.01 document,
+ before , without XHTML-style self-closing."""
+ r = env.curl_get(env.mkurl("http", "autoindex", "/listing/"))
+ assert r.response["status"] == 200
+ body = r.response["body"].decode()
+ meta = ''
+ assert meta in body, body
+ assert body.index(meta) < body.index(""), body
+
+ def test_generators_002_03_charset_meta_xhtml(self, env):
+ r = env.curl_get(env.mkurl("http", "autoindex", "/listing/?xhtml"))
+ assert r.response["status"] == 200
+ body = r.response["body"].decode()
+ meta = ''
+ assert meta in body, body
+ assert body.index(meta) < body.index(""), body
+
+ def test_generators_002_04_empty_charset_no_meta(self, env):
+ r = env.curl_get(env.mkurl("http", "autoindex",
+ "/listing/?nocharset"))
+ assert r.response["status"] == 200
+ assert "http-equiv" not in r.response["body"].decode()