[Jifty-commit] r5214 - in jifty/trunk: lib/Jifty/Plugin lib/Jifty/View/Static
Jifty commits
jifty-commit at lists.jifty.org
Wed Mar 12 15:29:09 EDT 2008
Author: alexmv
Date: Wed Mar 12 15:29:06 2008
New Revision: 5214
Modified:
jifty/trunk/ (props changed)
jifty/trunk/META.yml
jifty/trunk/lib/Jifty/Plugin/CompressedCSSandJS.pm
jifty/trunk/lib/Jifty/View/Static/Handler.pm
Log:
r28450 at kohr-ah: chmrr | 2008-03-12 15:28:28 -0400
* Static handler and CAS handler spit out same headers now
Modified: jifty/trunk/META.yml
==============================================================================
--- jifty/trunk/META.yml (original)
+++ jifty/trunk/META.yml Wed Mar 12 15:29:06 2008
@@ -3,7 +3,7 @@
build_requires:
ExtUtils::MakeMaker: 6.11
distribution_type: module
-generated_by: Module::Install version 0.680
+generated_by: Module::Install version 0.68
license: Perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.3.html
@@ -43,6 +43,7 @@
Module::CoreList: 0
Module::Install::Admin: 0.50
Module::Refresh: 0.09
+ Net::Akismet: 0
Net::LDAP: 0
Net::OAuth::Request: 0.05
Net::OpenID::Consumer: 0
@@ -101,6 +102,7 @@
HTML::Lint: 0
HTML::Mason: 1.3101
HTML::Mason::Plugin: 0
+ HTML::Scrubber: 0
HTTP::Cookies: 0
HTTP::Date: 0
HTTP::Server::Simple: 0.28
@@ -115,6 +117,7 @@
Locale::Maketext::Extract: 0.20
Locale::Maketext::Lexicon: 0.60
Log::Log4perl: 1.04
+ MIME::Base64::URLSafe: 0
MIME::Types: 0
Module::CoreList: 0
Module::Pluggable: 3.5
@@ -125,6 +128,7 @@
PadWalker: 0
Params::Validate: 0
Pod::Simple: 0
+ Regexp::Common: 0
SQL::ReservedWords: 0
Scalar::Defer: 0.12
Shell::Command: 0
Modified: jifty/trunk/lib/Jifty/Plugin/CompressedCSSandJS.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/CompressedCSSandJS.pm (original)
+++ jifty/trunk/lib/Jifty/Plugin/CompressedCSSandJS.pm Wed Mar 12 15:29:06 2008
@@ -237,18 +237,19 @@
}
my $obj = Jifty::CAS->retrieve('ccjs', $key);
+ my $compression = '';
+ $compression = 'gzip' if $obj->metadata->{deflate}
+ && Jifty::View::Static::Handler->client_accepts_gzipped_content;
+
Jifty->handler->apache->content_type($obj->metadata->{content_type});
- Jifty->handler->apache->header_out( 'Expires' => HTTP::Date::time2str( time + 31536000 ) );
+ Jifty::View::Static::Handler->send_http_header($compression, length($obj->content));
- if ($obj->metadata->{deflate} && Jifty::View::Static::Handler->client_accepts_gzipped_content ) {
+ if ( $compression ) {
Jifty->log->debug("Sending gzipped squished $name");
- Jifty->handler->apache->header_out( "Content-Encoding" => "gzip" );
- Jifty->handler->apache->send_http_header();
binmode STDOUT;
print $obj->content_deflated;
} else {
Jifty->log->debug("Sending squished $name");
- Jifty->handler->apache->send_http_header();
print $obj->content;
}
}
Modified: jifty/trunk/lib/Jifty/View/Static/Handler.pm
==============================================================================
--- jifty/trunk/lib/Jifty/View/Static/Handler.pm (original)
+++ jifty/trunk/lib/Jifty/View/Static/Handler.pm Wed Mar 12 15:29:06 2008
@@ -5,7 +5,6 @@
use Compress::Zlib ();
use HTTP::Date ();
-
package Jifty::View::Static::Handler;
use base qw/Jifty::Object/;
@@ -16,7 +15,7 @@
Jifty::View::Static::Handler - Jifty view handler for static files
-head1 DESCRIPTION
+=head1 DESCRIPTION
This class takes care of serving out static files for a Jifty application.
@@ -39,15 +38,12 @@
* if the browser doesn't accept gzipped content
send the content uncompressed
-
-=cut
-
-
=head2 new
Create a new static file handler. Likely, only the C<Jifty::Handler> needs to do this.
=cut
+
sub new {
my $class = shift;
@@ -221,12 +217,11 @@
sub send_file {
- my $self = shift;
- my $local_path = shift;
- my $mime_type = shift;
+ my $self = shift;
+ my $local_path = shift;
+ my $mime_type = shift;
my $compression = shift;
-
my $fh = IO::File->new( $local_path, 'r' );
if ( defined $fh ) {
binmode $fh;
@@ -238,36 +233,50 @@
Jifty->web->mason->clear_buffer if Jifty->web->mason;
my @file_info = stat($local_path);
- my $apache = Jifty->handler->apache;
-
- $apache->header_out( Status => 200 );
+ my $apache = Jifty->handler->apache;
$apache->content_type($mime_type);
- my $now = time();
-
- $apache->header_out('Cache-Control' => 'max-age=259200, public');
-
- $apache->header_out(Expires => HTTP::Date::time2str($now + 31536000)); # Expire in a year
- $apache->header_out('Last-Modified' => HTTP::Date::time2str( $file_info[9]));
- $apache->header_out('Content-Length' => $file_info[7]) unless ($compression eq 'gzip');
-
- $apache->header_out( "Content-Encoding" => "gzip") if ($compression eq 'gzip');
- $apache->send_http_header();
+ $self->send_http_header( $compression, $file_info[7], $file_info[9] );
- if ($compression eq 'gzip') {
+ if ( $compression eq 'gzip' ) {
local $/;
binmode STDOUT;
+
# XXX TODO: Cache this
print STDOUT Compress::Zlib::memGzip(<$fh>);
- } else{
+ }
+ else {
$apache->send_fd($fh);
}
close($fh);
return 1;
- } else {
+ }
+ else {
return undef;
}
}
+sub send_http_header {
+ my $self = shift;
+ my ($compression, $length, $modified) = @_;
+ my $now = time();
+ my $apache = Jifty->handler->apache;
+ $apache->header_out( Status => 200 );
+
+ # Expire in a year
+ $apache->header_out( 'Cache-Control' => 'max-age=31536000, public' );
+ $apache->header_out( 'Expires' => HTTP::Date::time2str( $now + 31536000 ) );
+
+ $apache->header_out(
+ 'Last-Modified' => HTTP::Date::time2str( $modified ) ) if $modified;
+
+ $apache->header_out( 'Content-Length' => $length )
+ unless ( $compression eq 'gzip' );
+ $apache->header_out( 'Content-Encoding' => "gzip" )
+ if ( $compression eq 'gzip' );
+
+ $apache->send_http_header();
+}
+
=head2 send_not_modified
More information about the Jifty-commit
mailing list