A piggy bank of commands, fixes, succinct reviews, some mini articles and technical opinions from a (mostly) Perl developer.

Jump to

Quick reference

Add headers or cookies to request in Mojolicious tests

When using Test::Mojo, sometimes you want to modify the request to add a cookie or custom headers.

# Define app
my $t = Test::Mojo->new("Test::App");
# Build request with custom headers
my %headers = ( 'X-Auth-Signature' => 'abcdef' );
my $tx = $t->ua->build_tx(POST => '/api/boards' => \%headers => json => { username => 'testuser' } );
# Add cookie
$tx->req->cookies({ name => 'cookie1', value => $jwt });
# Perform test
$t->request_ok($tx)->status_is(200);
.