##############################################################################
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
#
# Jabber
# Copyright (C) 1998-1999 The Jabber Team http://jabber.org/
#
##############################################################################
package HTTP::ProxyAutoConfig;
=head1 NAME
HTTP::ProxyAutoConfig - provides a unifed way to get the proxy information
=head1 SYNOPSIS
HTTP::ProxyAutoConfig is a module that allows perl scripts that need
access to proxy servers to utilize the standard proxy settings provided
by an IT department.
=head1 DESCRIPTION
This module provides a consistent method for finding the proxy server
needed to talk to for a given URL. It can handle parsing the http_proxy,
https_proxy, ftp_proxy, and http_auto_proxy variables to determine
what it is you want it to do. If you set the http_auto_proxy variable
it overrides the others and fetches the PAC file from there and uses
those settings.
Access to the proxy information is provided in a single function call
to FindProxyForURL(url,host). A string is returned that tells you what
to do, either "DIRECT", "PROXY host:port", or "SOCKS host:port".
The Proxy Auto Config format and rules are defined at Netscape:
http://home.netscape.com/eng/mozilla/2.0/relnotes/demo/proxy-live.html
The file basically works by defining a JavaScript function called
FindProxyForURL. This module fetches that file and converts the
JavaScript function into a Perl function and then defines the Perl
function with that converted data.
=head1 METHODS
new(url) - creates the FindProxyForURL function and the object.
The url argument is optional, and points to the auto-proxy
file provided on your network. If you do not specify a
url, then it will check the http_auto_proxy variable,
followed by the http_proxy, https_proxy, and ftp_proxy
variables.
my $pac = new HTTP::ProxyAutoConfig("http://foo.bar/auto-proxy.pac");
my $pac = new HTTP::ProxyAutoConfig();
FindProxyForURL(url,host) - takes the url, and the host (minus
port) from the URL, and determines the
action you should take to contact that
host. It returns one of three things:
DIRECT - connect directly to them
PROXY host:port - connect via the proxy
SOCKS host:port - connect via SOCKS
FindProxy(url) - calls the FindProxyForURL function and passes it the
correct options. This is just a wrapper.
Reload() - allows you to fetch the PAC again and regenerate the
FindProxyForURL function based on anything you might
have changed in the environment.
=head1 AUTHOR
By Ryan Eatmon in May of 2001
=head1 COPYRIGHT
This module is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
use strict;
use Carp;
use Sys::Hostname;
use IO::Socket;
use POSIX;
=1= |