Skip to contentSkip to conversation

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

PATCH In review Alp Toker 2 participants 3 messages Jun 15, 2016

lore
Share & tools
lore

Alp Toker

author
#0 lore raw

PATCH 1/1 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 claims to support 'application/xhtml+xml' by means of a glob in order to work around an insidious Internet Explorer bug.

---
 gitweb/gitweb.cgi |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
gitweb/gitweb.cgi +3 -2
index 3e2790c..3206435 100755
@@ -290,7 +290,8 @@ sub git_header_html {
 			}
 		}
 	}
-	print $cgi->header(-type=>'text/html',  -charset => 'utf-8', -status=> $status, -expires => $expires);
+	my $content_type = ($cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ && $cgi->Accept('application/xhtml+xml') ne 0) ? 'application/xhtml+xml' : '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">
@@ -298,7 +299,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"/>
Signature · 1 line
1.4.1.gbe4c7
#1 lore raw
Quoted 6 lines · Alp Toker

"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.

Ok.

Quoted 3 lines

It falls back to 'text/html' even if the user agent claims to support 'application/xhtml+xml' by means of a glob in order to work around an insidious Internet Explorer bug.

I do not care much about IE, but...

gitweb/gitweb.cgi sub git_header_html { · line 293

Quoted 1 line
gitweb/gitweb.cgi +1 -0
+	my $content_type = ($cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ && $cgi->Accept('application/xhtml+xml') ne 0) ? 'application/xhtml+xml' : 'text/html';

1. I would prefer something like this to be written with if-else, not with a conditional expression;

2. The "by means of a glob" hack needs to be left as a comment in the code to say why;

3. Did you really mean to say "ne 0"?

author
#2 lore raw
Quoted 5 lines · Junio C Hamano
Quoted 3 lines

It falls back to 'text/html' even if the user agent claims to support 'application/xhtml+xml' by means of a glob in order to work around an insidious Internet Explorer bug.

I do not care much about IE, but...

That makes the two of us. Still, it's probably worth not blocking out IE in case the need arises to check up on repositories from internet cafes when on holiday or the like.

Quoted 4 lines

gitweb/gitweb.cgi sub git_header_html { · line 293

Quoted 1 line
gitweb/gitweb.cgi +1 -0
+	my $content_type = ($cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ && $cgi->Accept('application/xhtml+xml') ne 0) ? 'application/xhtml+xml' : 'text/html';

1. I would prefer something like this to be written with if-else, not with a conditional expression;

Indeed, this line is a bit unwieldy. Will break it out.

Quoted 2 lines

2. The "by means of a glob" hack needs to be left as a comment in the code to say why;

Good plan.

Quoted 1 line

3. Did you really mean to say "ne 0"?

Well spotted. String comparison works, but != would be more sensible.

A revised patch is in the works.