Changeset 584

Show
Ignore:
Timestamp:
04/13/02 01:12:35
Author:
miyagawa
Message:

0.05

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Apache-No404Proxy/trunk/Changes

    r243 r584  
    11Revision history for Perl extension Apache::No404Proxy. 
     2 
     30.05  Sat Apr 13 01:11:42 JST 2002 
     4        * [API change] uses Google Web APIs (via SOAP::Lite) 
     5 
     60.04  Tue Mar 12 20:30:30 JST 2002 
     7        - fixed bug of multiple headers with the same name 
    28 
    390.03  Fri Sep  7 14:43:16 JST 2001 
  • Apache-No404Proxy/trunk/Makefile.PL

    r210 r584  
    88        'LWP::UserAgent'        => 1.80, 
    99        'URI'                   => 1.15, 
    10       'WWW::Cache::Google'    => 0.02, 
     10#     'WWW::Cache::Google'    => 0.02, 
    1111        'mod_perl'              => 1.21, 
     12        'SOAP::Lite'            => 0, 
    1213    }, 
    1314); 
  • Apache-No404Proxy/trunk/README

    r243 r584  
    11NAME 
    2     Apache::No404Proxy - 404 Redirecting Proxy 
     2    Apache::No404Proxy - 404 free Proxy 
    33 
    44SYNOPSIS 
    55      # in httpd.conf 
    66      PerlTransHandler Apache::No404Proxy # default uses ::Google 
     7      PerlSetVar GoogleLicenseKey ************** 
    78 
    89DESCRIPTION 
     
    1011 
    1112    Apache::No404Proxy serves as a proxy server, which automaticaly detects 
    12     404 responses and redirects your browser to Google cache. 
     13    404 responses and fetches Google cache via SOAP. You need your Google 
     14    account to use this module. See Google Web API terms for details. 
    1315 
    1416    Set your browser's proxy setting to Apache::No404Proxy based server, and 
    1517    it becomes 404 free now! 
    16  
    17     See also the section on "RESRICTIONS FOR USE" before you use this. 
    18  
    19 SUBCLASSING 
    20     Default cache archive is Google's one. Here is how you customize this. 
    21  
    22     *   Declare your URL translator class. 
    23  
    24     *   Inherit from Apache::No404Proxy. 
    25  
    26     *   Define "translate()" method. 
    27  
    28     That's all. Here is an example of implementation, extracted from 
    29     Apache::No404Proxy::Google. 
    30  
    31       package Apache::No404Proxy::Google; 
    32  
    33       use WWW::Cache::Google; 
    34       use base qw(Apache::No404Proxy); 
    35  
    36       sub translate { 
    37           my($class, $uri) = @_; 
    38           return WWW::Cache::Google->new($uri)->as_string; 
    39       } 
    40  
    41     Define "translate()" method as a class method. Argument $uri is a string 
    42     that represents URI. 
    43  
    44     At last, remember to add the following line to httpd.conf: 
    45  
    46       PerlTransHandler Apache::No404Proxy::Google 
    47  
    48 RESTRICTIONS FOR USE 
    49     READ THIS before you use this proxy, especially for the default Google 
    50     implementation. 
    51  
    52     This proxy may or may not break terms of service of Google. In fact, 
    53     Google prohibits *Automatic Query* without their permissions. See 
    54     http://www.google.com/terms_of_service.html for details. 
    55  
    56     Yes, this means you are recommended to contact staff at Google, 
    57     otherwise your IP address would be blacklisted from Google :( The one 
    58     you should get contact with is Ray Sidney, whose email addy is 
    59     <ray@google.com>. Thanks to Ray for his kindness. 
    6018 
    6119AUTHOR 
     
    6826 
    6927SEE ALSO 
    70     the Apache::ProxyPassThru manpage, the LWP::UserAgent manpage, the 
    71     Apache::No404Proxy::Google manpage 
     28    the Apache::ProxyPassThru manpage, http://www.google.com/apis/ 
    7229 
  • Apache-No404Proxy/trunk/lib/Apache/No404Proxy.pm

    r243 r584  
    33use strict; 
    44use vars qw($VERSION); 
    5 $VERSION = '0.03'
     5$VERSION = 0.05
    66 
    77use Apache::Constants qw(:response); 
     
    3232    my $res = LWP::UserAgent->new->simple_request($request); 
    3333    $r->content_type($res->header('Content-type')); 
     34 
     35    my $body; 
    3436    if ($res->code == 404 && ! $class->exclude($r->uri)) { 
    35         my $cache = $class->translate($r->uri); 
    36         # detect LOOP 
    37         { 
    38             my $origuri  = URI->new($r->uri); 
    39             my $cacheuri = URI->new($cache); 
    40             if ($origuri->host eq $cacheuri->host && 
    41                 $origuri->path eq $cacheuri->path) { 
    42                 require Apache::Log; 
    43                 $r->log->error('Apache::No404Proxy: detecting 404 loops. Stopped.'); 
    44                 return NOT_FOUND; 
    45             } 
     37        $body = $class->fetch($r); 
     38        unless ($body) { 
     39            require Apache::Log; 
     40            $r->log->error('Apache::No404Proxy: no cache found'); 
     41            return NOT_FOUND; 
    4642        } 
    47  
    48         $r->method('GET'); 
    49         $r->headers_in->unset('Content-length'); 
    50         $r->header_out(Location => $cache); 
    51         return REDIRECT; 
     43    } else { 
     44        $body = $res->content; 
    5245    } 
    5346 
    5447    $r->status($res->code); 
    5548    $r->status_line($res->status_line); 
    56     $res->scan(sub { $r->header_out(@_); }); 
     49    my $table = $r->headers_out; 
     50    $res->scan(sub { $table->add(@_); }); 
    5751    $r->send_http_header(); 
    58     $r->print($res->content); 
     52    $r->print($body); 
    5953 
    6054    return OK; 
     
    6761} 
    6862 
    69 sub translate
    70     my($class, $uri) = @_; 
     63sub fetch
     64    my($class, $r) = @_; 
    7165 
    7266    # Default to Google. Oddly enough delegating to my own child! 
    7367    require Apache::No404Proxy::Google; 
    74     Apache::No404Proxy::Google->translate($uri); 
     68    Apache::No404Proxy::Google->fetch($r); 
    7569} 
    7670 
     
    8175=head1 NAME 
    8276 
    83 Apache::No404Proxy - 404 Redirecting Proxy 
     77Apache::No404Proxy - 404 free Proxy 
    8478 
    8579=head1 SYNOPSIS 
     
    8781  # in httpd.conf 
    8882  PerlTransHandler Apache::No404Proxy # default uses ::Google 
     83  PerlSetVar GoogleLicenseKey ************** 
    8984 
    9085=head1 DESCRIPTION 
     
    9388 
    9489Apache::No404Proxy serves as a proxy server, which automaticaly 
    95 detects 404 responses and redirects your browser to Google cache. 
     90detects 404 responses and fetches Google cache via SOAP. You need your 
     91Google account to use this module. See Google Web API terms for 
     92details. 
    9693 
    9794Set your browser's proxy setting to Apache::No404Proxy based server, 
    9895and it becomes 404 free now! 
    99  
    100 See also L</"RESRICTIONS FOR USE"> before you use this. 
    101  
    102 =head1 SUBCLASSING 
    103  
    104 Default cache archive is Google's one. Here is how you customize this. 
    105  
    106 =over 4 
    107  
    108 =item * 
    109  
    110 Declare your URL translator class. 
    111  
    112 =item * 
    113  
    114 Inherit from Apache::No404Proxy. 
    115  
    116 =item * 
    117  
    118 Define C<translate()> method. 
    119  
    120 =back 
    121  
    122 That's all. Here is an example of implementation, extracted from 
    123 Apache::No404Proxy::Google. 
    124  
    125   package Apache::No404Proxy::Google; 
    126  
    127   use WWW::Cache::Google; 
    128   use base qw(Apache::No404Proxy); 
    129  
    130   sub translate { 
    131       my($class, $uri) = @_; 
    132       return WWW::Cache::Google->new($uri)->as_string; 
    133   } 
    134  
    135 Define C<translate()> method as a class method. Argument $uri is a 
    136 string that represents URI. 
    137  
    138 At last, remember to add the following line to httpd.conf: 
    139  
    140   PerlTransHandler Apache::No404Proxy::Google 
    141  
    142 =head1 RESTRICTIONS FOR USE 
    143  
    144 B<READ THIS> before you use this proxy, especially for the default 
    145 Google implementation. 
    146  
    147 This proxy may or may not break terms of service of Google. In fact, 
    148 Google prohibits I<Automatic Query> without their permissions. See 
    149 http://www.google.com/terms_of_service.html for details. 
    150  
    151 Yes, this means you are recommended to contact staff at Google, 
    152 otherwise your IP address would be blacklisted from Google :( The one 
    153 you should get contact with is Ray Sidney, whose email addy is 
    154 E<lt>ray@google.comE<gt>. Thanks to Ray for his kindness. 
    15596 
    15697=head1 AUTHOR 
     
    165106=head1 SEE ALSO 
    166107 
    167 L<Apache::ProxyPassThru>, L<LWP::UserAgent>, L<Apache::No404Proxy::Google> 
     108L<Apache::ProxyPassThru>, http://www.google.com/apis/ 
    168109 
    169110=cut 
  • Apache-No404Proxy/trunk/lib/Apache/No404Proxy/Google.pm

    r243 r584  
    33use strict; 
    44use vars qw($VERSION); 
    5 $VERSION = '0.01'
     5$VERSION = 0.05
    66 
    7 use WWW::Cache::Google
     7require Apache::No404Proxy
    88use base qw(Apache::No404Proxy); 
    99 
    10 sub translate { 
    11     my($class, $uri) = @_; 
    12     return WWW::Cache::Google->new($uri)->as_string; 
     10use SOAP::Lite; 
     11 
     12sub fetch { 
     13    my($class, $r) = @_; 
     14    my $key = $r->dir_config('GoogleLicenseKey') or die "You need GoogleLicenseKey to use this module"; 
     15    return SOAP::Lite 
     16        ->uri('urn:GoogleSearch') 
     17            ->proxy('http://api.google.com/search/beta2') 
     18                ->doGetCachedPage($key, $r->uri) 
     19                    ->result; 
    1320} 
    1421 
     
    2431  # in httpd.conf 
    2532  PerlTransHandler Apache::No404Proxy::Google 
     33  PerlSetVar GoogleLicenseKey ************** 
    2634 
    2735=head1 DESCRIPTION 
    2836 
    2937Apache::No404Proxy::Google is one of the implementations of 
    30 Apache::No404Proxy. This module uses WWW::Cache::Google to translate 
    31 URI to Google cache. 
    32  
    33 See L<Apache::No404Proxy/"SUBCLASSING"> for using other cache archive on 
    34 the web other than Google. 
    35  
    36 =head1 CAVEAT 
    37  
    38 See L<Apache::No404Proxy/"RESTRICTIONS FOR USE"> before using it. If 
    39 you have not done, B<DO IT NOW!> 
     38Apache::No404Proxy. This module uses SOAP::Lite to fetch Google cache. 
    4039 
    4140=head1 AUTHOR 
     
    4847=head1 SEE ALSO 
    4948 
    50 L<Apache::No404Proxy>, L<WWW::Cache::Google> 
     49L<Apache::No404Proxy>, L<SOAP::Lite>, L<WWW::Cache::Google> 
    5150 
    5251=cut