NAME
HTTP::Proxy - A pure Perl HTTP proxy
SYNOPSIS
use HTTP::Proxy;
# initialisation
my $proxy = HTTP::Proxy->new( port => 3128 );
# alternate initialisation
my $proxy = HTTP::Proxy->new;
$proxy->port( 3128 ); # the classical accessors are here!
# you can also use your own UserAgent
my $agent = LWP::RobotUA->new;
$proxy->agent( $agent );
# this is a MainLoop-like method
$proxy->start;
DESCRIPTION
This module implements a HTTP Proxy, using a HTTP::Daemon to accept client connections, and a LWP::UserAgent to ask for the requested pages.
METHODS
Constructor
Accessors
The HTTP::Proxy has several accessors. They are all AUTOLOADed.
Called with arguments, the accessor returns the current value. Called with a single argument, it set the current value and returns the previous one, in case you want to keep it.
If you call a read-only accessor with a parameter, this parameter will be ignored.
The defined accessors are (in alphabetical order):
- agent
-
The LWP::UserAgent object used internally to connect to remote sites.
- conn (read-only)
-
The number of connections processed by this HTTP::Proxy instance.
- control
-
The default hostname for controlling the proxy (see CONTROL). The default is "
proxy
", which corresponds to the URL http://proxy/, where port is the listening port of the proxy). - daemon
-
The HTTP::Daemon object used to accept incoming connections. (You usually never need this.)
- host
-
The proxy HTTP::Daemon host (default: 'localhost').
- logfh
-
A filehandle to a logfile (default: *STDERR).
- maxchild
-
The maximum number of child process the HTTP::Proxy object will spawn to handle client requests (default: 16).
- maxconn
-
The maximum number of connections the proxy will accept before returning from start(). 0 (the default) means never stop accepting connections.
- port
-
The proxy HTTP::Daemon port (default: 8080).
- url (read-only)
-
The url where the proxy can be reached.
- verbose
-
Be verbose in the logs (default: 0).
Here are the various log levels: 0 - All errors 1 - Requested URL, reponse status and total number of connections processed 2 - 3 - Subprocesses information (fork, wait, etc.) 4 - 5 - Full request and response headers are sent along
The start() method
This method works like Tk's MainLoop
: you hand over control to the HTTP::Proxy object you created and configured.
If maxconn
is not zero, start() will return after accepting at most that many connections.
Other methods
- log( $level, $message )
-
Adds $message at the end of
logfh
, if $level is greater thanverbose
, the log() method also prints a timestamp.
Callbacks
You can alter the way the default HTTP::Proxy works by pluging callbacks at different stages of the request/response handling.
(TO BE IMPLEMENTED)
BUGS
Some connections to the client are never closed. (HTTP::Proxy should handle the client and the server connection separately.)
TODO
* Provide an interface for logging.
* Provide control over the proxy through special URLs
AUTHOR
Philippe "BooK" Bruhat, <book@cpan.org>.
THANKS
Many people helped me during the development of this module, either on mailing-lists, irc, or over a beer in a pub...
So, in no particular order, thanks to Michael Schwern (testing while forking), Eric 'echo' Cholet (preforked processes).
COPYRIGHT
This module is free software; you can redistribute it or modify it under the same terms as Perl itself.