From: Frank Lichtenheld Date: Tue, 5 Aug 2008 22:48:34 +0000 (-0300) Subject: Packages::Dispatcher: Send 304 header if possible X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=f12ba374c31cd6192475847bd0549297a4c968de;p=deb%2Fpackages.git Packages::Dispatcher: Send 304 header if possible That should be a good way to cut down the load a bit. --- diff --git a/lib/Packages/Dispatcher.pm b/lib/Packages/Dispatcher.pm index 75264a0..c250011 100755 --- a/lib/Packages/Dispatcher.pm +++ b/lib/Packages/Dispatcher.pm @@ -30,6 +30,7 @@ use DB_File; use URI::Escape; use Benchmark ':hireswallclock'; use I18N::AcceptLanguage; +use Date::Parse; use Deb::Versions; use Packages::Config qw( $DBDIR $ROOT $TEMPLATEDIR $CACHEDIR @@ -92,6 +93,14 @@ sub do_dispatch { &Packages::Config::init( $homedir ); &Packages::DB::init(); + if ($input->http('If-Modified-Since') and + (my $modtime = str2time($input->http('If-Modified-Since'), 'UTC'))) { + if ($modtime < $Packages::DB::db_read_time) { + print $input->header(-status => 304); + exit; + } + } + my %PO_LANGUAGES = map { $_ => 1 } @LANGUAGES; my %DDTP_LANGUAGES = map { $_ => 1 } @DDTP_LANGUAGES; my $acc = I18N::AcceptLanguage->new(defaultLanguage => 'en'); @@ -331,7 +340,11 @@ sub do_dispatch { $page_content{params} = \%params; unless (@Packages::CGI::fatal_errors) { - print $input->header(-charset => $charset, -type => get_mime($opts{format}) ); + print $input->header(-charset => $charset, + -type => get_mime($opts{format}), + -last_modified => strftime("%a, %d %b %Y %T %z", + localtime($Packages::DB::db_read_time)), + ); #use Data::Dumper; #print '
'.Dumper(\%ENV, \%page_content, get_all_messages()).'
'; print $template->page( $what_to_do, { %page_content, %{ get_all_messages() } } );