W3C home > Mailing lists > Public > www-validator@w3.org > July 2007

Re: Validator doesn't send HTTP_ACCEPT headers, "Conflict between Mime Type and Document Type" warning is incorrect.

From: Andries Louw Wolthuizen <info@andrieslouw.nl>
Date: Tue, 31 Jul 2007 20:35:13 +0200
Message-ID: <c6e491920707311135uf1e6298m7e34ff5c11ce4337@mail.gmail.com>
To: www-validator@w3.org
Because I don't want to send application/xhtml+xml to (older) browsers that
don't send a HTTP accept header, I've set the default mime-type on
text/html.

My PHP script is now:
<?php
$charset = 'utf-8';
$mime = 'text/html';
if(!empty($_SERVER['HTTP_ACCEPT']) &&
stristr($_SERVER['HTTP_ACCEPT'],'application/xhtml+xml')){

if(preg_match('/application\/xhtml\+xml;q=([01]|0\.\d{1,3}|1\.0)/i',$_SERVER['HTTP_ACCEPT'],$matches)){
        $xhtml_q = $matches[1];

if(preg_match('/text\/html;q=q=([01]|0\.\d{1,3}|1\.0)/i',$_SERVER['HTTP_ACCEPT'],$matches)){
            $html_q = $matches[1];
            if((float)$xhtml_q >= (float)$html_q) {
                $mime = 'application/xhtml+xml';
            }
        }
    }else{
        $mime = 'application/xhtml+xml';
    }
}
if(stristr($_SERVER["HTTP_USER_AGENT"],"W3C_Validator") OR
stristr($_SERVER["HTTP_USER_AGENT"],"W3C_CSS_Validator") OR
stristr($_SERVER["HTTP_USER_AGENT"],"WDG_Validator")){
    $mime = "application/xhtml+xml";
}
if($mime == 'application/xhtml+xml') {
    $prolog_type = '<?xml version="1.0" encoding="'.$charset.'" ?>'.PHP_EOL;
}else{
    $prolog_type = '';
}
header('Content-Type: '.$mime.';charset='.$charset);
header('Vary: Accept');
echo $prolog_type;
?>

And:

<meta http-equiv="content-type" content="<?php echo $mime; ?>;
charset=utf-8" />

As you see, there is a workaround for the validator build-in, this is in my
opinion the only way to serve:
application/xhtml+xml to (modern) browsers that accept that
text/html to browsers that don't, but send a HTTP_ACCEPT header
text/html to (older) browsers that don't even send a HTTP_ACCEPT header
application/xhtml+xml to the validator

-- 
Met vriendelijke groet,
Andries Louw Wolthuizen
info@andrieslouw.nl

2007/7/31, Gez Lemon <gez@juicystudio.com>:
>
> On 31/07/07, Sierk Bornemann <sierkb@gmx.de> wrote:
> > Of course, this would be sane. But how to translate into a working
> > solution *without* asking the client's (in this case the valdator's)
> > accept header?
> > Any suggestion? Any algorithm out there (for PHP or JSP or other
> > frameworks) does rely on the browser's accept header and asks for the
> > *existance* of "application/xhtml+xml" in the accept header of the
> > client.
> > I, so far, have never seen any working solution, which asks for the
> > *non-existance* of  "application/xhtml+xml". All implementations of
> > the algorithm cited, I have seen so far, do ask for the *existance*
> > of "application/xhtml+xml".
> > So, how would you implement the *opposite* of that, if you have
> > requesting user agents, which provide an empty accept header string
> > or provide a meaningful "*" as the Internet Explorer does?
>
> You could first check that there is an HTTP_ACCEPT header. If not,
> deliver application/xhtml+xml; otherwise, test if
> application/xhtml+xml is in the accept header. That caters for all the
> scenarios you mentioned. The following serves text/html to IE,
> application/xhtml+xml to Firefox (and other browsers that state they
> can handle it), and application/xhtml+xml to the validator (as it
> doesn't send the accept header):
>
> header("Vary: Accept");
> if ($_SERVER[HTTP_ACCEPT]) {
>     if (stristr($_SERVER[HTTP_ACCEPT], "application/xhtml+xml") === FALSE)
> {
>         header("Content-Type: text/html; charset=utf-8");
>     }
>     else {
>         header("Content-Type: application/xhtml+xml; charset=utf-8");
>     }
> }
> else {
>     header("Content-Type: application/xhtml+xml; charset=utf-8");
> }
>
> Cheers,
>
> Gez
>
>
> --
> _____________________________
> Supplement your vitamins
> http://juicystudio.com
>
Received on Tuesday, 31 July 2007 18:35:16 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 25 April 2012 12:14:25 GMT