Another "headers_in" stabilization, this one is sure.
authorshort <>
Thu, 29 Sep 2005 09:27:57 +0000 (09:27 +0000)
committershort <>
Thu, 29 Sep 2005 09:27:57 +0000 (09:27 +0000)
Web.pm

diff --git a/Web.pm b/Web.pm
index 2a9406d..0885b11 100644 (file)
--- 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;