2

I need to convert LWP::UserAgent to Mojo::UserAgent to support async calls. Problem is I couldn't find the exact methods that matches the LWP::UserAgent methods below, for example, how do I convert the following LWP methods over to Mojo's? Any insight is greatly appreciated!

my $ua = new LWP::UserAgent ;

$ua->protocols_allowed( [ 'http', 'https' ] );

$ua->ssl_opts( 
 SSL_version=>'TLSv12', 
 verify_hostname=>0,  
 SSL_verify_mode=>SSL_VERIFY_NONE, 
 SSL_ca_file=>'ca_file.crt',
 SSL_cert_file=>'cert_file.crt',
 SSL_key_file=>'key_file.key',
 SSL_passwd_cb=> sub { return 'psswd'; }
);

$ua->credentials( $host_port, $realm, $user, $password ) ;

$ua->timeout( $timeOut ) ;

$ua->proxy( $theProxy ) ;

$ua->request( $requestObj );
santa100
  • 255
  • 1
  • 5

1 Answers1

1

By reading the documentation pages for LWP::UserAgent and Mojo::UserAgent, here is what I can see:

  • $ua->protocols_allowed() : This function is not available in Mojo::UserAgent
  • SSL_version : can be set for Mojo::UserAgent by calling IO::Socket::SSL::SSL_version()
  • verify_hostname : If verification is wanted, it can be called explicitly by calling IO::Socket::SSL::verify_hostname()
  • SSL_verify_mode : Can be set by calling IO::Socket::SSL::set_defaults(SSL_verify_mode => $mode)
  • SSL_ca_file : Mojo::UserAgent has a method $ua->ca() that can be used.
  • SSL_cert_file : Mojo::UserAgent has a method $ua->cert() that can be used
  • SSL_key_file : Mojo::UserAgent has a method $ua->key() that can be used
  • SSL_passwd_cb : Can be set by calling IO::Socket::SSL::set_defaults(SSL_passwd_cb => $cb)
  • $ua->credentials : I think these can be set by constructing a Mojo::URL object and passing it to the relevant request method.
  • $ua->timeout() : Mojo::UserAgent has a method $ua->connect_timeout() that can be used
  • $ua->proxy() : Mojo::UserAgent has a method $ua->proxy() that can be used.
  • $ua->request() : Mojo::UserAgent has a methods $ua->start() and $ua->start_p() that can be used.
Håkon Hægland
  • 39,012
  • 21
  • 81
  • 174