Skip to content

Instantly share code, notes, and snippets.

@preaction
Last active November 30, 2016 21:57
Show Gist options
  • Save preaction/8b58ee4791b94dab13d2bbf5cfc06bae to your computer and use it in GitHub Desktop.
Save preaction/8b58ee4791b94dab13d2bbf5cfc06bae to your computer and use it in GitHub Desktop.
use v5.020;
use warnings;
use Mojo::UserAgent;
sub bsos_helper {
my ( $server ) = @_;
my $ua = Mojo::UserAgent->new;
# XXX: Set proxy on $ua here
$ua->on( start => sub {
my ( $ua, $tx ) = @_;
$tx->req->url->host( 'example.com' );
$tx->req->url->port( '' );
} );
return $ua;
}
my $tx = bsos_helper( { server_id => 0 } )->get( '/foo' );
say "TX URL: " . $tx->req->url;
#######################################################################
sub build_tx {
my ( $server, $path ) = @_;
my $tx = Mojo::Transaction::HTTP->new;
$tx->req->url->scheme( 'http' );
$tx->req->url->host( 'example.com' );
$tx->req->url->port( '' );
# XXX: Set proxy on $tx->req here
$tx->req->url->path( $path );
return $tx;
}
$tx = build_tx( { server_id => 0 }, '/foo' );
$tx = Mojo::UserAgent->new->start( $tx );
say "TX URL: " . $tx->req->url;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment