| 1 | package WWW::2ch::UserAgent; | ||
| 2 | use strict; | ||
| 3 | |||
| 4 | use base qw( LWP::UserAgent ); | ||
| 5 | |||
| 6 | use HTTP::Request; | ||
| 7 | use HTTP::Date; | ||
| 8 | |||
| 9 | sub new { | ||
| 10 | my $class = shift; | ||
| 11 | my $ua = shift; | ||
| 12 | my $self = $class->SUPER::new(); | ||
| 13 | |||
| 14 | $ua = " ($ua)" if $ua; | ||
| 15 | $self->agent("Monazilla/1.00 WWW::2ch/$WWW::2ch::VERSION$ua"); | ||
| 16 | $self->timeout(15); | ||
| 17 | $self->max_redirect(0); | ||
| 18 | $self; | ||
| 19 | } | ||
| 20 | |||
| 21 | sub diff_request { | ||
| 22 | my ($self, $url, %opt) = @_; | ||
| 23 | |||
| 24 | my $req = HTTP::Request->new(GET => $url); | ||
| 25 | $req->header(Range => 'bytes=' . $opt{size} . '-') if $opt{size}; | ||
| 26 | $req->header('If-Modified-Since' => HTTP::Date::time2str($opt{time})) if $opt{time} && $opt{time} > 0; | ||
| 27 | |||
| 28 | $self->request($req); | ||
| 29 | } | ||
| 30 | |||
| 31 | 1; |