<?xml version="1.0" encoding="utf-8"?>
<!-- generator="Blooki/0.4803" -->
<feed version="0.3" xmlns="http://purl.org/atom/ns#"  xml:lang="en">
  <title mode="escaped" type="text/html">Blooki</title>
  <tagline mode="escaped" type="text/html">Grow what you know</tagline>
  <link rel="alternate" type="text/html" href="http://blooki.org/development/content-negotiation.atom/"/>
  <modified>2004-10-13T21:46:00Z</modified>
  <author><name>Paul Kulchenko</name></author>


  <entry>
    <title>Content negotiation</title>
    <content type="text/html" mode="escaped">&lt;p&gt;As Ian Hickson explained, &lt;a href="http://www.hixie.ch/advocacy/xhtml"&gt;Sending &lt;span class="caps"&gt;XHTML &lt;/span&gt;as text/html considered harmful&lt;/a&gt;, but it's fine "send &lt;span class="caps"&gt;XHTML &lt;/span&gt;as application/xhtml+xml to UAs that support it, and as text/html to legacy UAs."&lt;/p&gt;

&lt;p&gt;To implement this I've extended the content-type parameter in template, so that instead of &lt;code&gt;text/html&lt;/code&gt; it is now possible to write &lt;code&gt;application/xhtml+xml,text/html&lt;/code&gt;. Server will then use &lt;code&gt;Accept&lt;/code&gt; header to identify what content type should be served; it will serve &lt;code&gt;application/xhtml+xml&lt;/code&gt; to Firefox and &lt;code&gt;text/html&lt;/code&gt; to InternetExplorer. It also applies to &lt;span class="caps"&gt;RSS &lt;/span&gt;content types: Atom template has &lt;code&gt;application/atom+xml,application/xml&lt;/code&gt; as the content type.&lt;/p&gt;

&lt;p&gt;All this is done by the following lines of code (thanks to Gisle Aas for his &lt;span class="caps"&gt;HTTP&lt;/span&gt;::Negotiate):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt; my @types = split /,/, $template-&amp;gt;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 =&amp;gt; $request-&amp;gt;cgi-&amp;gt;http('accept');
 my $type = HTTP::Negotiate::choose($variants, $headers) || pop @types;&lt;/code&gt;&lt;/pre&gt;</content>
    <link rel="alternate" type="text/html" href="http://blooki.org/development/content-negotiation.atom/development/content-negotiation"/>
    <id>http://blooki.org/development/content-negotiation.atom/development/content-negotiation</id>
    <issued>2004-10-13T21:46:00Z</issued>
    <modified>2004-10-13T21:46:00Z</modified>
    
  </entry>


</feed>
