Skip to content

Commit

Permalink
Whoops, forgot to commit these. This is a version of
Browse files Browse the repository at this point in the history
LWP::Parallel::UserAgent that allows each request to use a different
proxy.
  • Loading branch information
jamiemccarthy committed Mar 24, 2004
1 parent bd7010a commit 3b2e27a
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Slash/Custom/ParUserAgent/MANIFEST
@@ -0,0 +1,3 @@
ParUserAgent.pm
Makefile.PL
MANIFEST
7 changes: 7 additions & 0 deletions Slash/Custom/ParUserAgent/Makefile.PL
@@ -0,0 +1,7 @@
use ExtUtils::MakeMaker;
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
WriteMakefile(
'NAME' => 'Slash::Custom::ParUserAgent',
'VERSION_FROM' => 'ParUserAgent.pm', # finds $VERSION
);
71 changes: 71 additions & 0 deletions Slash/Custom/ParUserAgent/ParUserAgent.pm
@@ -0,0 +1,71 @@
# This code is a part of Slash, and is released under the GPL.
# Copyright 1997-2003 by Open Source Development Network. See README
# and COPYING for more information, or see http://slashcode.com/.
# $Id$

# This overrides LWP::Parallel::UserAgent to allow multiple
# proxies to be used with a single scheme, indeed with a
# single URL. This is done by overriding proxy() to also
# push arguments onto an arrayref instance variable, and
# overriding _need_proxy() to, instead of using the scalar
# single proxy, pop the top proxy off the arrayref (and
# then push it back onto the end of the list, just in case).

package Slash::Custom::ParUserAgent;

use strict;
use base 'LWP::Parallel::UserAgent';
use vars qw($VERSION);

use LWP::Parallel::UserAgent;

($VERSION) = ' $Revision$ ' =~ /\$Revision:\s+([^\s]+)/;

sub _need_proxy {
my($self, $url) = @_;
$url = $HTTP::URI_CLASS->new($url) unless ref $url;

my $scheme = $url->scheme || return;
my $proxy;
if ($self->{slash_proxies}{$scheme}
&& @{$self->{slash_proxies}{$scheme}}) {
$proxy = shift @{$self->{slash_proxies}{$scheme}};
push @{$self->{slash_proxies}{$scheme}}, $proxy;
} else {
$proxy = $self->{'proxy'}{$scheme};
}
if ($proxy) {
if (@{ $self->{'no_proxy'} }) {
if (my $host = eval { $url->host }) {
for my $domain (@{ $self->{'no_proxy'} }) {
if ($host =~ /\Q$domain\E$/) {
LWP::Debug::trace("no_proxy configured");
return;
}
}
}
}
LWP::Debug::debug("SCP Proxied to $proxy");
return $HTTP::URI_CLASS->new($proxy);
}
LWP::Debug::debug('SCP Not proxied');
undef;
}

sub proxy {
my($self, $schemes, $proxyurl) = @_;
my @schemes = ref $schemes ? @$schemes : ( $schemes );
LWP::Debug::trace("SCP '@schemes' $proxyurl");
my $old;
for my $scheme (@schemes) {
$old = $self->{proxy}{$scheme};
$self->{proxy}{$scheme} = $proxyurl;
$self->{slash_proxies}{$scheme} ||= [ ];
push @{$self->{slash_proxies}{$scheme}}, $proxyurl;
}
return $old;
}

1;

__END__

0 comments on commit 3b2e27a

Please sign in to comment.