X-Git-Url: http://git.jankratochvil.net/?p=MyWeb.git;a=blobdiff_plain;f=Web.pm;h=0885b115be76a4e93b73507bc33a90eafec4bfe1;hp=2a9406d750c84dc8c0f0d2ba21e1a3ee582d69e7;hb=3558fcb4c2ca89db0f10e5427acdbdbc50a45bd0;hpb=fcaf410ca324e0fa3ad812545bf16e7bf4886b1e diff --git a/Web.pm b/Web.pm index 2a9406d..0885b11 100644 --- a/Web.pm +++ b/Web.pm @@ -1126,33 +1126,39 @@ my($class)=@_; # of at least # Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8b) Gecko/20050217 # http://validator.w3.org/ does not send ANY "Accept" headers! - $W->{"content_type"}="application/xhtml+xml" if !defined $W->{"content_type"} - && !$W->{"headers_in"}{"Accept"} - && ($W->{"headers_in"}{"User-Agent"}||"")=~m{^W3C_Validator/}i; - defined($W->{"content_type"}) or $W->{"content_type"}=$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 - # Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8b) Gecko/20050217 - # prefers "application/xhtml+xml" over "text/html" itself: - # text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 - negotiate_variant( - "id"=>"text/html", - "content-type"=>"text/html", - "qs"=>0.6, - (!$W->{"charset"} ? () : "charset"=>$W->{"charset"}), - "lang"=>$W->{"language"}, - ), - negotiate_variant( - "id"=>"application/xhtml+xml", - "content-type"=>"application/xhtml+xml", - "qs"=>0.6, - (!$W->{"charset"} ? () : "charset"=>$W->{"charset"}), - "lang"=>$W->{"language"}, - ), - # application/xml ? - # text/xml ? - ]); + if (!defined $W->{"content_type"}) { + # Be _stable_ for "headers_in". + my $accept=$W->{"headers_in"}{"Accept"}; + my $user_agent=$W->{"headers_in"}{"User-Agent"}||""; + $W->{"content_type"}="application/xhtml+xml" + if !$accept && $user_agent=~m{^W3C_Validator/}i; + # Be _stable_: + my $negotiated=$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 + # Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8b) Gecko/20050217 + # prefers "application/xhtml+xml" over "text/html" itself: + # text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 + negotiate_variant( + "id"=>"text/html", + "content-type"=>"text/html", + "qs"=>0.6, + (!$W->{"charset"} ? () : "charset"=>$W->{"charset"}), + "lang"=>$W->{"language"}, + ), + negotiate_variant( + "id"=>"application/xhtml+xml", + "content-type"=>"application/xhtml+xml", + "qs"=>0.6, + (!$W->{"charset"} ? () : "charset"=>$W->{"charset"}), + "lang"=>$W->{"language"}, + ), + # application/xml ? + # text/xml ? + ]); + $W->{"content_type"}=$negotiated if !defined $W->{"content_type"}; + } # mod_perl doc: If you set this header via the headers_out table directly, it # will be ignored by Apache. So do not do that. my $type;