Skip to content

Commit

Permalink
more custom request examples
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 8, 2015
1 parent a0ed48c commit 434428d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lib/Mojo/UserAgent.pm
Expand Up @@ -655,8 +655,8 @@ Generate L<Mojo::Transaction::HTTP> object with
L<Mojo::UserAgent::Transactor/"tx">.
# Request with custom cookie
my $tx = $ua->build_tx(GET => 'example.com');
$tx->req->cookies({name => 'foo', value => 'bar'});
my $tx = $ua->build_tx(GET => 'http://example.com/account');
$tx->req->cookies({name => 'user', value => 'sri'});
$tx = $ua->start($tx);
# Deactivate gzip compression
Expand All @@ -665,7 +665,7 @@ L<Mojo::UserAgent::Transactor/"tx">.
$tx = $ua->start($tx);
# Interrupt response by raising an error
my $tx = $ua->build_tx(GET => 'example.com');
my $tx = $ua->build_tx(GET => 'http://example.com');
$tx->res->on(progress => sub {
my $res = shift;
return unless my $server = $res->headers->server;
Expand Down
11 changes: 8 additions & 3 deletions lib/Test/Mojo.pm
Expand Up @@ -913,10 +913,15 @@ Perform request and check for transport errors.
my $tx = $t->ua->build_tx(FOO => '/test.json' => json => {foo => 1});
$t->request_ok($tx)->status_is(200)->json_is({success => 1});
# Request with custom cookie
my $tx = $t->ua->build_tx(GET => '/account');
$tx->req->cookies({name => 'user', value => 'sri'});
$t->request_ok($tx)->status_is(200)->text_is('head > title' => 'Hello sri');
# Custom WebSocket handshake
my $tx = $t->ua->build_websocket_tx('/foo');
$tx->req->headers->remove('User-Agent');
$t->request_ok($tx)->message_ok->message_is('bar')->finish_ok;
my $tx = $t->ua->build_websocket_tx('/foo');
$tx->req->headers->remove('User-Agent');
$t->request_ok($tx)->message_ok->message_is('bar')->finish_ok;
=head2 reset_session
Expand Down

0 comments on commit 434428d

Please sign in to comment.