App-Pod
view release on metacpan or search on metacpan
t/cpan/Mojo2/UserAgent.pm view on Meta::CPAN
delete $self->{pid};
$self->_finish( $_, 1 ) for keys %{ $self->{connections} // {} };
return $self;
}
sub _connect {
my ( $self, $loop, $tx, $handle ) = @_;
my $t = $self->transactor;
my ( $proto, $host, $port ) =
$handle ? $t->endpoint( $tx ) : $t->peer( $tx );
my %options = ( timeout => $self->connect_timeout );
if ( $proto eq 'http+unix' ) { $options{path} = $host }
else { @options{qw(address port)} = ( $host, $port ) }
$options{socket_options} = $self->socket_options;
$options{handle} = $handle if $handle;
# SOCKS
if ( $proto eq 'socks' ) {
@options{qw(socks_address socks_port)} = @options{qw(address port)};
( $proto, @options{qw(address port)} ) = $t->endpoint( $tx );
my $userinfo = $tx->req->via_proxy( 0 )->proxy->userinfo;
@options{qw(socks_user socks_pass)} = split /:/, $userinfo if $userinfo;
}
# TLS
if ( $options{tls} = $proto eq 'https' ) {
map { $options{"tls_$_"} = $self->$_ } qw(ca cert key);
$options{tls_options}{SSL_verify_mode} = 0x00 if $self->insecure;
}
t/cpan/Mojo2/UserAgent.pm view on Meta::CPAN
$id = $self->_connect( $loop, $old, $handle );
$self->{connections}{$id} = $c;
}
);
}
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
t/cpan/Mojo2/UserAgent.pm view on Meta::CPAN
# 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 );
my $url = $tx->req->url;
if ( !$url->is_abs && ( my $server = $self->server ) ) {
my $base = $loop == $self->ioloop ? $server->url : $server->nb_url;
( run in 0.252 second using v1.01-cache-2.11-cpan-27979f6cc8f )