[Jifty-commit] r1784 - jifty/trunk/lib/Jifty/View/Mason

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Wed Aug 9 13:35:39 EDT 2006


Author: clkao
Date: Wed Aug  9 13:35:36 2006
New Revision: 1784

Modified:
   jifty/trunk/lib/Jifty/View/Mason/Handler.pm

Log:
gzip mason output as well.


Modified: jifty/trunk/lib/Jifty/View/Mason/Handler.pm
==============================================================================
--- jifty/trunk/lib/Jifty/View/Mason/Handler.pm	(original)
+++ jifty/trunk/lib/Jifty/View/Mason/Handler.pm	Wed Aug  9 13:35:36 2006
@@ -78,20 +78,23 @@
     my $m = HTML::Mason::Request->instance;
     my $r = Jifty->handler->apache;
 
-    $r->content_type || $r->content_type('text/html; charset=utf-8'); # Set up a default
-
-    if ($r->content_type =~ /charset=([\w-]+)$/ ) {
-        my $enc = $1;
-	if (lc($enc) =~ /utf-?8/) {
-            binmode *STDOUT, ":utf8";
+    unless ($r->http_header_sent or not $m->auto_send_headers) {
+	my $want_gzip = 0;
+	if (Jifty->handler->cgi->http('Accept-Encoding') =~ /\bgzip\b/) {
+	    ++$want_gzip;
+	    $r->header_out( "Content-Encoding" => "gzip" );
 	}
-	else {
-            binmode *STDOUT, ":encoding($enc)";
+
+	my $enc_layer;
+	$r->content_type || $r->content_type('text/html; charset=utf-8'); # Set up a default
+	if ($r->content_type =~ /charset=([\w-]+)$/ ) {
+	    $enc_layer = lc($1) =~ /utf-?8/ ? ':utf8' : ":encoding($1)"; 
 	}
-    }
 
-    unless ($r->http_header_sent or not $m->auto_send_headers) {
         $r->send_http_header();
+
+	binmode *STDOUT, ":gzip(lazy)" if $want_gzip;
+	binmode *STDOUT, $enc_layer if $enc_layer;
     }
 
     # We could perhaps install a new, faster out_method here that


More information about the Jifty-commit mailing list