Provide <?xml ... ?> header only if XHTML got negotiated.
authorshort <>
Mon, 22 Aug 2005 01:57:35 +0000 (01:57 +0000)
committershort <>
Mon, 22 Aug 2005 01:57:35 +0000 (01:57 +0000)
$W->{"user_agent"} is now set to "" if not defined.
Force XHTML for: http://validator.w3.org/

Web.pm

diff --git a/Web.pm b/Web.pm
index 8b1859c..88b0aff 100644 (file)
--- a/Web.pm
+++ b/Web.pm
@@ -202,8 +202,8 @@ my($class,%args)=@_;
                $W->{"args"}{$name}=[@vals];
                }
 
-       do { $W->{$_}=$W->{"r"}->headers_in()->{"Accept"}     if !defined $W->{$_}; } for ("accept");
-       do { $W->{$_}=$W->{"r"}->headers_in()->{"User-Agent"} if !defined $W->{$_}; } for ("user_agent");
+       do { $W->{$_}=$W->{"r"}->headers_in()->{"Accept"}         if !defined $W->{$_}; } for ("accept");
+       do { $W->{$_}=$W->{"r"}->headers_in()->{"User-Agent"}||"" if !defined $W->{$_}; } for ("user_agent");
 
        $W->{"browser"}=HTTP::BrowserDetect->new($W->{"user_agent"});
 
@@ -788,7 +788,10 @@ my($class)=@_;
        #   https://bugzilla.mozilla.org/show_bug.cgi?id=120556
        # of at least
        #   Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8b) Gecko/20050217
-       my $mime=$class->Negotiate_choose([
+       my $mime;
+       # http://validator.w3.org/ does not send ANY "Accept" headers!
+       $mime||="application/xhtml+xml" if $W->{"user_agent"}=~m{^W3C_Validator/}i;
+       $mime||=$class->Negotiate_choose([
                        # Put the fallback variant as the first one.
                        # Rate both variants the same to prefer "text/html" for undecided clients.
                        # At least
@@ -813,9 +816,7 @@ my($class)=@_;
                        # text/xml ?
                        ]);
        $W->{"r"}->content_type("$mime; charset=$client_charset");
-       if (1) { # (|| !$msie_major || $msie_major>=4) # TODO:dyn
-               Wprint '<?xml version="1.0" encoding="'.$client_charset.'"?>'."\n";
-               }
+       Wprint '<?xml version="1.0" encoding="'.$client_charset.'"?>'."\n" if $mime=~m{^application/\w+[+]xml$};
        Wprint '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'."\n";
        Wprint '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.$lang.'">'."\n";
        my $title=$W->{"title_prefix"}.join("",map({ ': '.$_; } ($W->{"title"} || ())));