Changeset 982

Show
Ignore:
Timestamp:
12/21/06 22:22:57 (2 years ago)
Author:
bchoate
Message:

Applied rules for handling If-Modified-Since headers for feed results from David Phillips. BugId: 33103

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/wheeljack/lib/MT/App/Search.pm

    r717 r982  
    1313 
    1414use File::Spec; 
    15 use MT::Util qw( encode_html ); 
     15use MT::Util qw(encode_html ts2epoch); 
     16use HTTP::Date qw(str2time time2str); 
    1617 
    1718use MT::App; 
     
    350351            "Building results failed: [_1]", $build->errstr)); 
    351352    $res = $app->_set_form_elements($res); 
     353 
    352354    if (defined($ctx->stash('content_type'))) { 
    353355        $app->{no_print_body} = 1; 
    354         $app->send_http_header($ctx->stash('content_type')); 
    355         $app->print($res); 
     356        if ($app->{searchparam}{Template} eq 'feed') { 
     357            my $last_update; 
     358            for (@results) { 
     359                my $created_on = ts2epoch($_->{blog}, $_->{entry}->created_on); 
     360                $last_update = $created_on if $created_on > $last_update; 
     361            } 
     362            my $mod_since = $app->get_header('If-Modified-Since'); 
     363 
     364            if ( !@results || ($last_update && $mod_since && ($last_update <= str2time($mod_since))) ) { 
     365                $app->response_code(304); 
     366                $app->response_message('Not Modified'); 
     367                $app->send_http_header($ctx->stash('content_type')); 
     368            } else { 
     369                $app->set_header('Last-Modified', time2str($last_update)) if $last_update; 
     370                $app->send_http_header($ctx->stash('content_type')); 
     371                $app->print($res); 
     372            } 
     373        } else { 
     374            $app->send_http_header($ctx->stash('content_type')); 
     375            $app->print($res); 
     376        } 
    356377    } 
    357378    $res;