13 Oct 2004
at 21:46
in development
As Ian Hickson explained, Sending XHTML as text/html considered harmful, but it's fine "send XHTML as application/xhtml+xml to UAs that support it, and as text/html to legacy UAs."
To implement this I've extended the content-type parameter in template, so that instead of text/html it is now possible to write application/xhtml+xml,text/html. Server will then use Accept header to identify what content type should be served; it will serve application/xhtml+xml to Firefox and text/html to InternetExplorer. It also applies to RSS content types: Atom template has application/atom+xml,application/xml as the content type.
All this is done by the following lines of code (thanks to Gisle Aas for his HTTP::Negotiate):
my @types = split /,/, $template->content_type;
my $pos = 0; # ::Negotiate sorts results by quality and then by size (asc)
my $variants = [map {[$_, 1, $_, (undef) x 3, ++$pos]} reverse @types];
my $headers = new HTTP::Headers Accept => $request->cgi->http('accept');
my $type = HTTP::Negotiate::choose($variants, $headers) || pop @types;