Changeset 267

Show
Ignore:
Timestamp:
03/04/06 11:40:25
Author:
daisuke
Message:

Add conditional GET support
Xango < 1.02 suffered from a prep_request buglet. require newer

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plagger/Makefile.PL

    r265 r267  
    4545        -default => 0, 
    4646        recommends('POE'), 
    47         recommends('Xango'), 
     47        recommends('Xango', 1.02), # avoid prep_request bug 
    4848        recommends('XML::Feed', 0.08), 
    4949        recommends('Cache::FastMmap'), 
  • trunk/plagger/lib/Plagger/Plugin/Aggregator/Simple.pm

    r256 r267  
    4545 
    4646    unless ($remote) { 
    47         $context->log(error => "Parsing $url failed. " . XML::Feed->errstr); 
     47        $context->log(error => "Parsing $url failed. " . ($@ || XML::Feed->errstr)); 
    4848        next; 
    4949    } 
  • trunk/plagger/lib/Plagger/Plugin/Aggregator/Xango.pm

    r165 r267  
    2222    Plagger::Plugin::Aggregator::Xango::Crawler->spawn( 
    2323        Plugin => $self, 
     24        UseCache => exists $self->conf->{use_cache} ? 
     25            $self->conf->{use_cache} : 1, 
    2426    ); 
    2527    Xango::Broker::Push->spawn(%xango_args); 
     
    4749use strict; 
    4850use POE; 
     51use Storable qw(freeze thaw); 
    4952use XML::Feed; 
    5053 
     
    5558 
    5659    POE::Session->create( 
    57         heap => { PLUGIN => $args{Plugin} }, 
     60        heap => { PLUGIN => $args{Plugin}, USE_CACHE => $args{UseCache} }, 
    5861        package_states => [ 
    59             $class => [ qw(_start _stop apply_policy handle_response) ] 
     62            $class => [ qw(_start _stop apply_policy prep_request handle_response) ] 
    6063        ] 
    6164    ); 
     
    6467sub _start { $_[KERNEL]->alias_set('xghandler') } 
    6568sub _stop  { } 
     69sub prep_request { 
     70    return unless $_[HEAP]->{USE_CACHE}; 
     71 
     72    my $job = $_[ARG0]; 
     73    my $req = $_[ARG1]; 
     74    my $plugin = $_[HEAP]->{PLUGIN}; 
     75 
     76    my $ref = $plugin->cache->get($job->uri); 
     77    if ($ref) { 
     78        $req->if_modified_since($ref->{LastModified}) 
     79            if $ref->{LastModified}; 
     80        $req->header('If-None-Match', $ref->{ETag}) 
     81            if $ref->{ETag}; 
     82    } 
     83} 
     84 
    6685sub handle_response { 
    6786    my $job = $_[ARG0]; 
     
    7190    my $url    = $job->uri; 
    7291 
     92    return unless $r->is_success; 
    7393    $plugin->handle_feed($url, $r->content_ref); 
     94    if ($_[HEAP]->{USE_CACHE}) { 
     95        $plugin->cache->set( 
     96            $job->uri, 
     97            {ETag => $r->header('ETag'), 
     98                LastModified => $r->header('Last-Modified')} 
     99        ); 
     100    } 
    74101} 
    75102