Apache-No404Proxy

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

Revision history for Perl extension Apache::No404Proxy.

0.05  Sat Apr 13 01:11:42 JST 2002
	* [API change] uses Google Web APIs (via SOAP::Lite)

0.04  Tue Mar 12 20:30:30 JST 2002
	- fixed bug of multiple headers with the same name

0.03  Fri Sep  7 14:43:16 JST 2001
	- Added note about permissions before using.
	- Added Ray's email address as Google contact address.

MANIFEST  view on Meta::CPAN

Changes
MANIFEST
Makefile.PL
README
lib/Apache/No404Proxy.pm
lib/Apache/No404Proxy/Google.pm
t/00_no404proxy.t

Makefile.PL  view on Meta::CPAN

use ExtUtils::MakeMaker;
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
WriteMakefile(
    'NAME'	=> 'Apache::No404Proxy',
    'VERSION_FROM' => 'lib/Apache/No404Proxy.pm', # finds $VERSION
    'PREREQ_PM' => {
	'LWP::UserAgent' 	=> 1.80,
	'URI' 			=> 1.15,
#	'WWW::Cache::Google' 	=> 0.02,
	'mod_perl' 		=> 1.21,
	'SOAP::Lite'            => 0,
    },
);

README  view on Meta::CPAN

NAME
    Apache::No404Proxy - 404 free Proxy

SYNOPSIS
      # in httpd.conf
      PerlTransHandler Apache::No404Proxy # default uses ::Google
      PerlSetVar GoogleLicenseKey **************

DESCRIPTION
    Oops, 404 Not found. But wait..., there is a Google cache!

    Apache::No404Proxy serves as a proxy server, which automaticaly detects
    404 responses and fetches Google cache via SOAP. You need your Google
    account to use this module. See Google Web API terms for details.

    Set your browser's proxy setting to Apache::No404Proxy based server, and
    it becomes 404 free now!

AUTHOR
    Tastuhiko Miyagawa <miyagawa@bulknews.net>

    This library is free software; you can redistribute it and/or modify it
    under the same terms as Perl itself.

    This module comes WITHOUT ANY WARRANTY.

SEE ALSO

lib/Apache/No404Proxy.pm  view on Meta::CPAN

package Apache::No404Proxy;

use strict;
use vars qw($VERSION);
$VERSION = 0.05;

use Apache::Constants qw(:response);
use LWP::UserAgent;
use URI;

sub handler($$) {

lib/Apache/No404Proxy.pm  view on Meta::CPAN

    }

    if ($r->method eq 'POST') {
	$request->content(scalar $r->content);
    }

    my $res = LWP::UserAgent->new->simple_request($request);
    $r->content_type($res->header('Content-type'));

    my $body;
    if ($res->code == 404 && ! $class->exclude($r->uri)) {
	$body = $class->fetch($r);
	unless ($body) {
	    require Apache::Log;
	    $r->log->error('Apache::No404Proxy: no cache found');
	    return NOT_FOUND;
	}
    } else {
	$body = $res->content;
    }

    $r->status($res->code);
    $r->status_line($res->status_line);
    my $table = $r->headers_out;
    $res->scan(sub { $table->add(@_); });

lib/Apache/No404Proxy.pm  view on Meta::CPAN

# default excludes image files
sub exclude {
    my($class, $uri) = @_;
    return $uri =~ /\.(?:gif|jpe?g|png)$/i;
}

sub fetch {
    my($class, $r) = @_;

    # Default to Google. Oddly enough delegating to my own child!
    require Apache::No404Proxy::Google;
    Apache::No404Proxy::Google->fetch($r);
}


1;
__END__

=head1 NAME

Apache::No404Proxy - 404 free Proxy

=head1 SYNOPSIS

  # in httpd.conf
  PerlTransHandler Apache::No404Proxy # default uses ::Google
  PerlSetVar GoogleLicenseKey **************

=head1 DESCRIPTION

Oops, 404 Not found. But wait..., there is a Google cache!

Apache::No404Proxy serves as a proxy server, which automaticaly
detects 404 responses and fetches Google cache via SOAP. You need your
Google account to use this module. See Google Web API terms for
details.

Set your browser's proxy setting to Apache::No404Proxy based server,
and it becomes 404 free now!

=head1 AUTHOR

Tastuhiko Miyagawa <miyagawa@bulknews.net>

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

This module comes B<WITHOUT ANY WARRANTY>.

lib/Apache/No404Proxy/Google.pm  view on Meta::CPAN

package Apache::No404Proxy::Google;

use strict;
use vars qw($VERSION);
$VERSION = 0.05;

require Apache::No404Proxy;
use base qw(Apache::No404Proxy);

use SOAP::Lite;

sub fetch {
    my($class, $r) = @_;
    my $key = $r->dir_config('GoogleLicenseKey') or die "You need GoogleLicenseKey to use this module";
    return SOAP::Lite
	->uri('urn:GoogleSearch')
	    ->proxy('http://api.google.com/search/beta2')
		->doGetCachedPage($key, $r->uri)
		    ->result;
}

1;
__END__

=head1 NAME

Apache::No404Proxy::Google - Implementation of Apache::No404Proxy

=head1 SYNOPSIS

  # in httpd.conf
  PerlTransHandler Apache::No404Proxy::Google
  PerlSetVar GoogleLicenseKey **************

=head1 DESCRIPTION

Apache::No404Proxy::Google is one of the implementations of
Apache::No404Proxy. This module uses SOAP::Lite to fetch Google cache.

=head1 AUTHOR

Tastuhiko Miyagawa <miyagawa@bulknews.net>

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

=head1 SEE ALSO

L<Apache::No404Proxy>, L<SOAP::Lite>, L<WWW::Cache::Google>

=cut

t/00_no404proxy.t  view on Meta::CPAN

use strict;
use Test;
BEGIN { plan tests => 1 }

use Apache::No404Proxy;
ok(1);



( run in 3.144 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )