Changeset 1940

Show
Ignore:
Timestamp:
04/07/07 20:04:31
Author:
daisuke
Message:

properly convert HTTP::Response to URI::Fetch::Response so Aggregator::Simple understands it. This requires the latest Gungho from svn (as of this writing)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plagger/lib/Plagger/Plugin/Aggregator/Gungho.pm

    r1939 r1940  
    1010__PACKAGE__->mk_accessors($_) for qw(gungho_plugin); 
    1111 
     12sub TO_URI_FETCH_RESPONSE 
     13{ 
     14    my ($r) = @_; 
     15 
     16    my $ufr = URI::Fetch::Response->new(); 
     17    $ufr->http_status($r->code); 
     18    $ufr->http_response($r); 
     19    $ufr->status( 
     20        $r->previous && $r->previous->code == &HTTP::Status::RC_MOVED_PERMANENTLY ? &URI::Fetch::URI_MOVED_PERMANENTLY : 
     21        $r->code == &HTTP::Status::RC_GONE ? &URI::Fetch::URI_GONE : 
     22        $r->code == &HTTP::Status::RC_NOT_MODIFIED ? &URI::Fetch::URI_NOT_MODIFIED : 
     23        &URI::Fetch::URI_OK 
     24    ); 
     25    $ufr->etag($r->header('ETag')); 
     26    $ufr->last_modified($r->header('Last-Modified')); 
     27    $ufr->uri($r->request->uri); 
     28    $ufr->content($r->content); 
     29    $ufr->content_type($r->content_type); 
     30 
     31    return $ufr; 
     32} 
     33 
    1234sub handle_response 
    1335{ 
    1436    my $self = shift; 
    1537    my $c    = shift; 
     38    my $req  = shift; 
    1639    my $res  = shift; 
     40    my $ufr  = TO_URI_FETCH_RESPONSE($res); 
    1741 
    18     $self->next::method($c, $res); 
    19     $self->gungho_plugin->handle_feed($res->request->uri, $res->content_ref); 
     42    $self->next::method($c, $req, $res); 
     43 
     44    my $plugin   = $self->gungho_plugin; 
     45    my $url      = $req->url; 
     46    my $feed_url = Plagger::FeedParser->discover($ufr); 
     47    if ($url eq $feed_url) { 
     48        $plugin->handle_feed($url, \$ufr->content, $req->notes('feed')); 
     49    } elsif ($feed_url) { 
     50        my $clone = $req->clone; 
     51        $clone->uri($feed_url); 
     52        $plugin->gungho->send_request($clone); 
     53    } else { 
     54        return; 
     55    } 
    2056} 
    2157 
     
    2662use Gungho::Request; 
    2763 
    28 __PACKAGE__->mk_accessors($_) for qw(requests); 
     64__PACKAGE__->mk_accessors($_) for qw(gungho requests); 
    2965 
    3066sub register 
     
    4682    return unless $url =~ m!^https?://!i; 
    4783 
     84    my $req = Gungho::Request->new(GET => $url); 
     85    $req->notes( feed => $args->{feed} ); 
    4886    $context->log(info => "Fetch $url"); 
    49     push @{ $self->requests }, Gungho::Request->new(GET => $url)
     87    push @{ $self->requests }, $req
    5088} 
    5189 
     
    6199        } 
    62100    }); 
     101 
     102    $self->gungho($g); 
     103 
    63104    $g->provider()->requests( $self->requests ); 
    64105    $g->provider()->has_requests( 1 );