Re: XHTML 1.0 Content-Negotiation

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 UTC