App-Pod

 view release on metacpan or  search on metacpan

t/01-usage-simple.t  view on Meta::CPAN

              put
              put_p
              request_timeout
              server
              socket_options
              start
              start
              start_p
              term_escape
              transactor
              weaken
              websocket
              websocket_p
            }
        ],
    },
    {
        name            => "class_options - Mojo2::UserAgent2",
        input           => [qw( Mojo2::UserAgent2 --class_options )],
        expected_output => [ "", "Class not found: Mojo2::UserAgent2" ],
    },

t/01-usage-simple.t  view on Meta::CPAN

            "max_redirects",      "max_response_size",
            "monkey_patch",       "options",
            "options_p",          "patch",
            "patch_p",            "post",
            "post_p",             "prepare",
            "proxy",              "put",
            "put_p",              "request_timeout",
            "server",             "socket_options",
            "start",              "start",
            "start_p",            "term_escape",
            "transactor",         "weaken",
            "websocket",          "websocket_p"
        ],
    },
    {
        name  => "class_options, tool_options - Mojo2::UserAgent2",
        input => [qw( Mojo2::UserAgent2 --class_options --tool_options )],
        expected_output => [
            "--all",      "--class_options",
            "--co",       "--dd",
            "--doc",      "--dump",

t/cpan/Mojo2/UserAgent.pm  view on Meta::CPAN


# "Fry: Since when is the Internet about robbing people of their privacy?
#  Bender: August 6, 1991."
use Mojo::IOLoop;
use Mojo::Promise;
use Mojo::Util qw(monkey_patch term_escape);
use Mojo::UserAgent::CookieJar;
use Mojo::UserAgent::Proxy;
use Mojo::UserAgent::Server;
use Mojo::UserAgent::Transactor;
use Scalar::Util qw(weaken);

use constant DEBUG => $ENV{MOJO_CLIENT_DEBUG} || 0;

has ca                 => sub { $ENV{MOJO_CA_FILE} };
has cert               => sub { $ENV{MOJO_CERT_FILE} };
has connect_timeout    => sub { $ENV{MOJO_CONNECT_TIMEOUT} || 10 };
has cookie_jar         => sub { Mojo::UserAgent::CookieJar->new };
has inactivity_timeout => sub { $ENV{MOJO_INACTIVITY_TIMEOUT} // 40 };
has insecure           => sub { $ENV{MOJO_INSECURE} };
has 'max_response_size';

t/cpan/Mojo2/UserAgent.pm  view on Meta::CPAN

        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;
    }

    weaken $self;
    my $id;
    return $id = $loop->client(
        %options => sub {
            my ( $loop, $err, $stream ) = @_;

            # Connection error
            return unless $self;
            return $self->_error( $id, $err ) if $err;

            # Connection established

t/cpan/Mojo2/UserAgent.pm  view on Meta::CPAN

    my $res = $old->closed->res->finish;
    $res->error( { message => 'Premature connection close' } )
      if $close && !$res->code && !$res->error;

    # Always remove connection for WebSockets
    return $self->_remove( $id ) if $old->is_websocket;
    $self->cookie_jar->collect( $old );

    # Upgrade connection to WebSocket
    if ( my $new = $self->transactor->upgrade( $old ) ) {
        weaken $self;
        $new->on( resume => sub { $self->_write( $id ) } );
        $c->{cb}( $self, $c->{tx} = $new );
        return $new->client_read( $old->res->content->leftovers );
    }

    # CONNECT requests always have a follow-up request
    $self->_reuse( $id, $close ) unless uc $old->req->method eq 'CONNECT';
    $res->error( { message => $res->message, code => $res->code } )
      if $res->is_error;
    $c->{cb}( $self, $old ) unless $self->_redirect( $c, $old );

t/cpan/Mojo2/UserAgent.pm  view on Meta::CPAN

      $c->{ioloop}->stream( $id )->timeout( $self->inactivity_timeout );
    my $tx     = $c->{tx}->connection( $id );
    my $handle = $stream->handle;
    unless ( $handle->isa( 'IO::Socket::UNIX' ) ) {
        $tx->local_address( $handle->sockhost )
          ->local_port( $handle->sockport );
        $tx->remote_address( $handle->peerhost )
          ->remote_port( $handle->peerport );
    }

    weaken $self;
    $tx->on( resume => sub { $self->_write( $id ) } );
    $self->_write( $id );
}

sub _read {
    my ( $self, $id, $chunk ) = @_;

    # Corrupted connection
    return $self->_remove( $id ) unless my $tx = $self->{connections}{$id}{tx};
    warn term_escape "-- Client <<< Server (@{[_url($tx)]})\n$chunk\n" if DEBUG;

t/cpan/Mojo2/UserAgent.pm  view on Meta::CPAN

    $_->prepare( $tx ) for $self->proxy, $self->cookie_jar;
    my $max = $self->max_response_size;
    $tx->res->max_message_size( $max ) if defined $max;
    $self->emit( start => $tx );

    # Allow test servers sharing the same event loop to clean up connections
    !$loop->next_tick( sub { } ) and $loop->one_tick unless $loop->is_running;
    return undef unless my $id = $self->_connection( $loop, $tx, $cb );

    if ( my $t = $self->request_timeout ) {
        weaken $self;
        $self->{connections}{$id}{timeout} ||=
          $loop->timer( $t => sub { $self->_error( $id, 'Request timeout' ) } );
    }

    return $id;
}

sub _url { shift->req->url->to_abs }

sub _write {
    my ( $self, $id ) = @_;

    # Protect from resume event recursion
    my $c = $self->{connections}{$id};
    return if !( my $tx = $c->{tx} ) || $c->{writing};
    local $c->{writing} = 1;
    my $chunk = $tx->client_write;
    warn term_escape "-- Client >>> Server (@{[_url($tx)]})\n$chunk\n" if DEBUG;
    return unless length $chunk;

    weaken $self;
    $c->{ioloop}->stream( $id )
      ->write( $chunk => sub { $self && $self->_write( $id ) } );
}

1;

=encoding utf8

=head1 NAME



( run in 0.280 second using v1.01-cache-2.11-cpan-65fba6d93b7 )