Last active
November 30, 2016 21:57
-
-
Save preaction/8b58ee4791b94dab13d2bbf5cfc06bae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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