git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] gitweb: Send XHTML as 'application/xhtml+xml' where possible

From
Alp Toker <alp@atoker.com>
Date
Jul 11, 2006, 10:19 UTC
Message-ID
<11526131781900-git-send-email-alp@atoker.com>
In-Reply-To
<11526131782190-git-send-email-alp@atoker.com>

"The 'text/html' media type [RFC2854] is primarily for HTML, not for XHTML. In general, this media type is NOT suitable for XHTML."

This patch makes gitweb use content negotiation to conservatively send pages as Content-Type 'application/xhtml+xml' when the user agent explicitly claims to support it.

It falls back to 'text/html' even if the user agent appears to implicitly support 'application/xhtml+xml' due to a '*/*' glob, working around an insidious bug in Internet Explorer where sending the correct media type prevents the page from being displayed.

Signed-off-by: Alp Toker <alp@atoker.com>
---
 gitweb/gitweb.cgi |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/gitweb/gitweb.cgi b/gitweb/gitweb.cgi
index 2e87de4..bd9b9de 100755
--- a/gitweb/gitweb.cgi
+++ b/gitweb/gitweb.cgi
@@ -293,7 +293,17 @@ sub git_header_html {
 			}
 		}
 	}
-	print $cgi->header(-type=>'text/html',  -charset => 'utf-8', -status=> $status, -expires => $expires);
+	my $content_type;
+	# require explicit support from the UA if we are to send the page as
+	# 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
+	# we have to do this because MSIE sometimes globs '*/*', pretending to
+	# support xhtml+xml but choking when it gets what it asked for.
+	if ($cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ && $cgi->Accept('application/xhtml+xml') != 0) {
+		$content_type = 'application/xhtml+xml';
+	} else {
+		$content_type = 'text/html';
+	}
+	print $cgi->header(-type=>$content_type,  -charset => 'utf-8', -status=> $status, -expires => $expires);
 	print <<EOF;
 <?xml version="1.0" encoding="utf-8"?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
@@ -301,7 +311,7 @@ sub git_header_html {
 <!-- git web interface v$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
 <!-- git core binaries version $git_version -->
 <head>
-<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
+<meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
 <meta name="robots" content="index, nofollow"/>
 <title>$title</title>
 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
-- 
1.4.1.g97c7-dirty
Previous: Alp TokerNext: Alp Toker
Message 2 of 17 in “Typo fix”
  1. Typo fixAlp Toker, Jul 11, 2006
  2. gitweb: Send XHTML as 'application/xhtml+xml' where possibleAlp Toker, Jul 11, 2006
  3. gitweb: Include a site name in page titlesAlp Toker, Jul 11, 2006
  4. gitweb: Use the git binary in the search path by defaultAlp Toker, Jul 11, 2006
  5. git-send-email: Remove redundant Reply-To headerAlp Toker, Jul 11, 2006
  6. Install built-ins as symlinksAlp Toker, Jul 11, 2006
  7. Andreas EricssonJul 11, 2006
  8. Johannes SchindelinJul 11, 2006
  9. Alp TokerJul 11, 2006
  10. Johannes SchindelinJul 11, 2006
  11. Petr BaudisJul 11, 2006
  12. Alex RiesenJul 12, 2006
  13. Petr BaudisJul 11, 2006
  14. Junio C HamanoJul 11, 2006
  15. Martin LanghoffJul 11, 2006
  16. Junio C HamanoJul 11, 2006
  17. Pavel RoskinJul 11, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.