W3C home > Mailing lists > Public > www-qa@w3.org > August 2005

Re: XHTML 1.0 Content-Negotiation

From: Dominique HazaŽl-Massieux <dom@w3.org>
Date: Fri, 19 Aug 2005 12:46:00 +0200
To: James Pickering <jp29@cox.net>
Cc: www-qa@w3.org
Message-Id: <1124448360.5590.241.camel@stratustier>

Le samedi 06 aoŻt 2005 ŗ 21:49 +0100, Jim Ley a ťcrit :
> "James Pickering" <jp29@cox.net>
> >Their Technical Department was not encouraging about
> >effecting Content-Negotiation but I found that inserting the following
> >PHP code ..........
> > [...]
>
> Unfortunately this is incorrect, and would violate HTTP 1.1, the Accept 
> header is considerably richer in what it can say than the above uses.

FWIW, I have been using the PHP class available at:
http://jking.dark-phantasy.com/code/php/class.contentnegotiation.phps to
deal with my content negotiation needs. I'm not sure how complete it is
in terms of parsing correctly HTTP headers (anybody knows a test suite I
could use?), but at least it passes the following tests:
<?php
require_once("class.contentnegotiation.php");

$tests = array("text/html,application/xhtml+xml" => "text/html",
               "text/html;q=0.1, application/xhtml+xml;q=0.5" =>
"application/xhtml+xml",
               "text/html;q=0.1, application/xhtml+xml;q=0" =>
"text/html",
               "text/html;q=\"0.5\",application/xhtml+xml;q=\"0.5\"" =>
"text/html");

foreach($tests as $input=>$output) {
  $_SERVER["HTTP_ACCEPT"]=$input;
  $conneg = new contentNegotiation();
   if ($conneg->compareQ("text/html,application/xhtml+xml")==$output) {
    echo "Success\n" ;
  } else {
    echo "failure\n" ;
  }
}
?>

(I've found many sites that proposed to deal with the particular case of
conneg between application/xhtml+xml and text/html, e.g.:
http://www.autisticcuckoo.net/archive.php?id=2004/11/03/content-negotiation
http://keystonewebsites.com/articles/mime_type.php
http://mathibus.com/archive/2005/04/php-xhtml-content-negotiation
but none of their code seems to pass correctly the tests above)

Depending on the feedback I get, I'll update
http://www.w3.org/2003/01/xhtml-mimetype/content-negotiation
accordingly.

Dom
-- 
Dominique HazaŽl-Massieux - http://www.w3.org/People/Dom/
W3C/ERCIM
mailto:dom@w3.org
Received on Friday, 19 August 2005 10:46:08 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Sunday, 6 December 2009 12:14:01 GMT