[Catalyst-commits] r9188 - in Catalyst-View-TT-XHTML/1.000/trunk: . lib/Catalyst/View/ContentNegotiation

t0m at dev.catalyst.perl.org t0m at dev.catalyst.perl.org
Tue Feb 3 22:09:15 GMT 2009


Author: t0m
Date: 2009-02-03 22:09:14 +0000 (Tue, 03 Feb 2009)
New Revision: 9188

Modified:
   Catalyst-View-TT-XHTML/1.000/trunk/Changes
   Catalyst-View-TT-XHTML/1.000/trunk/lib/Catalyst/View/ContentNegotiation/XHTML.pm
Log:
Avoid manging request headers by cloning them. Neater solutions welcome.

Modified: Catalyst-View-TT-XHTML/1.000/trunk/Changes
===================================================================
--- Catalyst-View-TT-XHTML/1.000/trunk/Changes	2009-02-03 21:51:13 UTC (rev 9187)
+++ Catalyst-View-TT-XHTML/1.000/trunk/Changes	2009-02-03 22:09:14 UTC (rev 9188)
@@ -1,6 +1,7 @@
 1.100
   - Refactor into a Moose Role for use with alternate views. (rafl)
   - Additional documentation (t0m)
+  - Clone request headers rather than changing them (t0m)
 1.004
   - Nick the OSX fragment out of the Catalyst::Runtime Makefile.PL to
     beat my Mac into generating a correct dist. (t0m)

Modified: Catalyst-View-TT-XHTML/1.000/trunk/lib/Catalyst/View/ContentNegotiation/XHTML.pm
===================================================================
--- Catalyst-View-TT-XHTML/1.000/trunk/lib/Catalyst/View/ContentNegotiation/XHTML.pm	2009-02-03 21:51:13 UTC (rev 9187)
+++ Catalyst-View-TT-XHTML/1.000/trunk/lib/Catalyst/View/ContentNegotiation/XHTML.pm	2009-02-03 22:09:14 UTC (rev 9188)
@@ -28,10 +28,10 @@
 
 after process => sub {
     my ($self, $c) = @_;
-    if ($c->request->header('Accept') && $c->response->headers->{'content-type'} =~ m|text/html|) {
-        $self->pragmatic_accept($c);
-        my $var = choose($self->variants, $c->request->headers);
-        if ($var eq 'xhtml') {
+    if ( my $accept = $self->pragmatic_accept($c) and $c->response->headers->{'content-type'} =~ m|text/html|) {
+        my $headers = $c->request->headers->clone;
+        $headers->header('Accept' => $accept);
+        if ( choose($self->variants, $headers) eq 'xhtml') {
             $c->response->headers->{'content-type'} =~ s|text/html|application/xhtml+xml|;
         }
     }
@@ -39,13 +39,14 @@
 
 sub pragmatic_accept {
     my ($self, $c) = @_;
-    my $accept = $c->request->header('Accept');
+    my $accept = $c->request->header('Accept') or return;
     if ($accept =~ m|text/html|) {
         $accept =~ s!\*/\*\s*([,]+|$)!*/*;q=0.5$1!;
-    } else {
+    } 
+    else {
         $accept =~ s!\*/\*\s*([,]+|$)!text/html,*/*;q=0.5$1!;
     }
-    $c->request->header('Accept' => $accept);
+    return $accept;
 }
 
 1;




More information about the Catalyst-commits mailing list