App-Pod
view release on metacpan or search on metacpan
t/01-usage-simple.t view on Meta::CPAN
' delete - Perform blocking DELETE reque ...',
' delete_p - Same as "delete", but perform ...',
' get - Perform blocking GET request ...',
' get_p - Same as "get", but performs a ...',
' head - Perform blocking HEAD request ...',
' head_p - Same as "head", but performs ...',
' inactivity_timeout - Maximum amount of time in sec ...',
' insecure - Do not require a valid TLS ce ...',
' ioloop - Event loop object to use for ...',
' key - Path to TLS key file, default ...',
' max_connections - Maximum number of keep-alive ...',
' max_redirects - Maximum number of redirects t ...',
' max_response_size - Maximum response size in byte ...',
' options - Perform blocking OPTIONS requ ...',
' options_p - Same as "options", but perfor ...',
' patch - Perform blocking PATCH reques ...',
' patch_p - Same as "patch", but performs ...',
' post - Perform blocking POST request ...',
' post_p - Same as "post", but performs ...',
' proxy - Proxy manager, defaults to a ...',
' put - Perform blocking PUT request ...',
t/cpan/Mojo2/UserAgent.pm view on Meta::CPAN
( $loop, $new ) => sub {
my ( $self, $tx ) = @_;
# Real transaction
$old->previous( $tx )->req->via_proxy( 0 );
my $c = $self->{connections}{$id} =
{ cb => $cb, ioloop => $loop, tx => $old };
# CONNECT failed
return $self->_error( $id, 'Proxy connection failed' )
if $tx->error || !$tx->res->is_success || !$tx->keep_alive;
# Start real transaction without TLS upgrade
return $self->_process( $id )
unless $tx->req->url->protocol eq 'https';
# TLS upgrade before starting the real transaction
my $handle = $loop->stream( $id )->steal_handle;
$self->_remove( $id );
$id = $self->_connect( $loop, $old, $handle );
$self->{connections}{$id} = $c;
t/cpan/Mojo2/UserAgent.pm view on Meta::CPAN
sub _connection {
my ( $self, $loop, $tx, $cb ) = @_;
# Reuse connection
my ( $proto, $host, $port ) = $self->transactor->endpoint( $tx );
my $id;
if ( $id = $self->_dequeue( $loop, "$proto:$host:$port", 1 ) ) {
warn "-- Reusing connection $id ($proto://$host:$port)\n" if DEBUG;
@{ $self->{connections}{$id} }{qw(cb tx)} = ( $cb, $tx );
$tx->kept_alive( 1 ) unless $tx->connection;
$self->_process( $id );
return $id;
}
# CONNECT request to proxy required
if ( my $id = $self->_connect_proxy( $loop, $tx, $cb ) ) { return $id }
# New connection
$tx->res->error( { message => "Unsupported protocol: $proto" } )
and return $loop->next_tick( sub { $self->$cb( $tx ) } )
t/cpan/Mojo2/UserAgent.pm view on Meta::CPAN
}
sub _reuse {
my ( $self, $id, $close ) = @_;
# Connection close
my $c = $self->{connections}{$id};
my $tx = delete $c->{tx};
my $max = $self->max_connections;
return $self->_remove( $id )
if $close || !$tx || !$max || !$tx->keep_alive || $tx->error;
# Keep connection alive
my $queue = $self->{queue}{ $c->{ioloop} } //= [];
$self->_remove( shift( @$queue )->[1] ) while @$queue && @$queue >= $max;
push @$queue, [ join( ':', $self->transactor->endpoint( $tx ) ), $id ];
}
sub _start {
my ( $self, $loop, $tx, $cb ) = @_;
# Application server
$self->emit( prepare => $tx );
t/cpan/Mojo2/UserAgent.pm view on Meta::CPAN
say "WebSocket message via JSON: $hash->{msg}";
$tx->finish;
});
$tx->send({json => {msg => 'Hello World!'}});
});
Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
=head1 DESCRIPTION
L<Mojo::UserAgent> is a full featured non-blocking I/O HTTP and WebSocket user agent, with IPv6, TLS, SNI, IDNA,
HTTP/SOCKS5 proxy, UNIX domain socket, Comet (long polling), Promises/A+, keep-alive, connection pooling, timeout,
cookie, multipart, gzip compression and multiple event loop support.
All connections will be reset automatically if a new process has been forked, this allows multiple processes to share
the same L<Mojo::UserAgent> object safely.
For better scalability (epoll, kqueue) and to provide non-blocking name resolution, SOCKS5 as well as TLS support, the
optional modules L<EV> (4.32+), L<Net::DNS::Native> (0.15+), L<IO::Socket::Socks> (0.64+) and L<IO::Socket::SSL>
(2.009+) will be used automatically if possible. Individual features can also be disabled with the C<MOJO_NO_NNR>,
C<MOJO_NO_SOCKS> and C<MOJO_NO_TLS> environment variables.
t/cpan/Mojo2/UserAgent.pm view on Meta::CPAN
my $key = $ua->key;
$ua = $ua->key('/etc/tls/client.crt');
Path to TLS key file, defaults to the value of the C<MOJO_KEY_FILE> environment variable.
=head2 max_connections
my $max = $ua->max_connections;
$ua = $ua->max_connections(5);
Maximum number of keep-alive connections that the user agent will retain before it starts closing the oldest ones,
defaults to C<5>. Setting the value to C<0> will prevent any connections from being kept alive.
=head2 max_redirects
my $max = $ua->max_redirects;
$ua = $ua->max_redirects(3);
Maximum number of redirects the user agent will follow before it fails, defaults to the value of the
C<MOJO_MAX_REDIRECTS> environment variable or C<0>.
=head2 max_response_size
( run in 1.219 second using v1.01-cache-2.11-cpan-df04353d9ac )