Skip to content

Instantly share code, notes, and snippets.

@dagolden
Created November 5, 2010 02:28
Show Gist options
  • Save dagolden/663557 to your computer and use it in GitHub Desktop.
Save dagolden/663557 to your computer and use it in GitHub Desktop.
sub get {
my($self, $uri, $cb_gen) = @_;
my $http = HTTP::Lite->new;
$http->http11_mode(1); # hopefully, CPAN mirrors can handle this
my $retries = 0;
while ( $retries++ < 5 ) {
my $rc = $self->_make_request( $http, $uri, $data_cb );
if ( $rc == 401 ) {
last unless $self->_prepare_auth( $http, 'non_proxy' );
}
elsif ( $rc == 407 ) {
last unless $self->_prepare_auth( $http, 'proxy' );
}
elsif ( $rc == 301 || $rc == 302 ) {
$uri = $self->_get_redirect( $http, $uri );
}
else {
last;
}
}
return $http;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment