Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: AnyEvent::HTTP::LWP::UserAgent with LWP::Authen::NTLM causes recusrive blocking wait?

by sectokia (Beadle)
on Feb 09, 2021 at 01:05 UTC ( #11128120=note: print w/replies, xml ) Need Help??


in reply to AnyEvent::HTTP::LWP::UserAgent with LWP::Authen::NTLM causes recusrive blocking wait?

I couldn't see any way to make this work with existing CPAN packaged, so I made my own module to do HTTP Get with NTLM auth AnyEvent asynronously in case anyone cares and wants to build on this:
package AnyEventHTTPGetNTLM; use strict; use warnings; use AnyEvent; use AnyEvent::HTTP; use Authen::NTLM; # # AnyEventHTTPGetNTLM # # Uses AnyEvent::HTTP and Authen::NTLM to do an async HTTP GET on a NT +LM protected server. # Requires a hash ref as argument containing: # user => NTLM user name # pass => NTLM password # domain => NTLM domain # url => The URL to get # timeout => Time out of HTTP requests # cb => Call back subroutine, which will be called with result ($data +, $headers) as arguments. # # Returns object which must be kept in scope for callback. # The objects 'cv' item is a condition var for the overall async opera +tion. # sub new { my ($class,$args) = @_; my $self = $args; bless $self, $class; $self->{'cv'} = AnyEvent->condvar; $self->{'timeout'} = 10 if (!$self->{'timeout'}); $self->{'sub'} = sub { my ($data, $headers) = @_; if (($headers->{'Status'} eq '401') && ($headers->{'www-authen +ticate'} eq 'NTLM')) { ntlm_domain($self->{'domain'}); ntlm_user($self->{'user'}); ntlm_password($self->{'pass'}); my $auth = "NTLM ".ntlm(); ntlm_reset(); $self->{'cv'}->begin; $self->{'phase1'} = http_request GET => $self->{'url'}, ti +meout => $self->{'timeout'}, headers => {'Authorization' => $auth }, +presistent => 1, $self->{'sub'}; } elsif (($headers->{'Status'} eq '401') && ($headers->{'www-aut +henticate'} =~ m/^NTLM /)) { my $challange = $headers->{'www-authenticate'}; $challange =~ s/^NTLM //; ntlm(); my $auth = "NTLM ".ntlm($challange); ntlm_reset(); $self->{'cv'}->begin; $self->{'phase2'} = http_request GET => $self->{'url'}, ti +meout => $self->{'timeout'}, headers => {'Authorization' => $auth }, +persistent => 1, $self->{'sub'}; } else { $self->{'cb'}->($data,$headers); } $self->{'cv'}->end; }; $self->{'cv'}->begin; $self->{'phase0'} = http_request GET => $self->{'url'}, timeout => + $self->{'timeout'}, persistent => 1, $self->{'sub'}; return $self; } 1;
Example usage:
use AnyEventHTTPGetNTLM; use Data::Dumper qw(Dumper); my $async = new AnyEventHTTPGetNTLM({ 'domain' => 'myDomain', 'user' => 'fred', 'pass' => 'secret', 'url' => 'http://example.com:999/getsomething', 'timeout' => 10, 'cb' => sub { my ($data,$headers) = @_; print Dumper $headers; print Dumper $data; }, }); $async->{'cv'}->recv;
  • Comment on Re: AnyEvent::HTTP::LWP::UserAgent with LWP::Authen::NTLM causes recusrive blocking wait?
  • Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11128120]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2021-04-11 03:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?