gitweb: Send XHTML as 'application/xhtml+xml' where possible
"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> Signed-off-by: Junio C Hamano <junkio@cox.net>
Alp Toker committed
Jul 11, 2006 at 11:19 UTC
f6801d669ee11f0d5e67b2e86aec270d2a225224
1 file changed
+12
-2
gitweb/gitweb.cgi
+12
-2
@@ -293,7 +293,17 @@ sub git_header_html {
293
}
294
}
295
}
296
- print $cgi->header(-type=>'text/html', -charset => 'utf-8', -status=> $status, -expires => $expires);
296
+ my $content_type;
297
+ # require explicit support from the UA if we are to send the page as
298
+ # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
299
+ # we have to do this because MSIE sometimes globs '*/*', pretending to
300
+ # support xhtml+xml but choking when it gets what it asked for.
301
+ if ($cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ && $cgi->Accept('application/xhtml+xml') != 0) {
302
+ $content_type = 'application/xhtml+xml';
303
+ } else {
304
+ $content_type = 'text/html';
305
+ }
306
+ print $cgi->header(-type=>$content_type, -charset => 'utf-8', -status=> $status, -expires => $expires);
307
print <<EOF;
308
<?xml version="1.0" encoding="utf-8"?>
309
<!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 {
311
<!-- git web interface v$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
312
<!-- git core binaries version $git_version -->
313
<head>
304
-<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
314
+<meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
315
<meta name="robots" content="index, nofollow"/>
316
<title>$title</title>
317
<link rel="stylesheet" type="text/css" href="$stylesheet"/>