Mojo::T...on::HTTP(3)

πŸ’… Mojo::T...on::HTTP(3) β€” like, the HTTP transaction page, bestie

okay so real talk: this is the manual page for Mojo::Transaction::HTTP, and up in the header it gets squished down to Mojo::T...on::HTTP(3) because terminal widths are rude. It's user contributed Perl documentation, and it is genuinely iconic. Let's get into it. πŸŽ€


✨ NAME ✨

Mojo::Transaction::HTTP β€” HTTP transaction. That's the whole vibe. One transaction. Very main character. πŸ¦‹


🌸 SYNOPSIS 🌸

Like, here's the whole thing in action, no notes:

use Mojo::Transaction::HTTP;

# Client
my $tx = Mojo::Transaction::HTTP->new;
$tx->req->method('GET');
$tx->req->url->parse('http://example.com');
$tx->req->headers->accept('application/json');
say $tx->res->code;
say $tx->res->headers->content_type;
say $tx->res->body;
say $tx->remote_address;

# Server
my $tx = Mojo::Transaction::HTTP->new;
say $tx->req->method;
say $tx->req->url->to_abs;
say $tx->req->headers->accept;
say $tx->remote_address;
$tx->res->code(200);
$tx->res->headers->content_type('text/plain');
$tx->res->body('Hello World!');

Two whole moods in one synopsis β€” client side and server side. We love a dual-threat. πŸ’œ


🫢 DESCRIPTION 🫢

Mojo::Transaction::HTTP is, like, a container for HTTP transactions. It's based on RFC 7230 <https://tools.ietf.org/html/rfc7230> and RFC 7231 <https://tools.ietf.org/html/rfc7231>. So it's standards-compliant and cute. Periodt. ✨


πŸ”₯ EVENTS πŸ”₯

Mojo::Transaction::HTTP inherits all events from Mojo::Transaction, and it can emit these new ones too. Obsessed.

πŸ’« request

$tx->on(request => sub ($tx) {...});

Emitted when a request is ready and needs to be handled. Like, the request is up and it's asking you to do something about it.

$tx->on(request => sub ($tx) { $tx->res->headers->header('X-Bender' => 'Bite my shiny metal ass!') });

X-Bender really said it with their whole chest, honestly. πŸ’€

πŸ’« resume

$tx->on(resume => sub ($tx) {...});

Emitted when the transaction is resumed. Welcome back, king. πŸ‘‘

πŸ’« unexpected

$tx->on(unexpected => sub ($tx, $res) {...});

Emitted for unexpected "1xx" responses that will be ignored. Rude of them, but okay.

$tx->on(unexpected => sub ($tx) { $tx->res->on(finish => sub { say 'Follow-up response is finished.' }) });

🌈 ATTRIBUTES 🌈

Mojo::Transaction::HTTP inherits all attributes from Mojo::Transaction and implements this new one. Yes, just the one. Quality over quantity, iykyk.

πŸ’– previous

my $previous = $tx->previous;
$tx          = $tx->previous(Mojo::Transaction::HTTP->new);

The previous transaction that triggered this follow-up transaction β€” usually a Mojo::Transaction::HTTP object.

# Paths of previous requests
say $tx->previous->previous->req->url->path;
say $tx->previous->req->url->path;

Look at that double previous. It's giving ancestry dot com. 🌳


⭐ METHODS ⭐

Mojo::Transaction::HTTP inherits all methods from Mojo::Transaction and implements these new ones. Strap in, there's a bunch. 🎒

πŸ¦‹ client_read

$tx->client_read($bytes);

Read data client-side β€” this is the one used to implement user agents like Mojo::UserAgent. 🧚

πŸ¦‹ client_write

my $bytes = $tx->client_write;

Write data client-side β€” again, used to implement user agents like Mojo::UserAgent.

πŸ¦‹ is_empty

my $bool = $tx->is_empty;

Check the transaction for a "HEAD" request and a "1xx", 204 or 304 response. Basically a vibe check for emptiness. πŸ’…

πŸ¦‹ keep_alive

my $bool = $tx->keep_alive;

Check if the connection can be kept alive. Not to be dramatic but this is literally life or death for the connection. 😭

πŸ¦‹ redirects

my $redirects = $tx->redirects;

Returns an array reference with all previous transactions that preceded this follow-up transaction.

# Paths of all previous requests
say $_->req->url->path for @{$tx->redirects};

All of them. Every single one. We're going through the whole group chat history, no skipping. πŸ™ˆ

πŸ¦‹ resume

$tx = $tx->resume;

Resume the transaction. That's it, that's the method. Slay.

πŸ¦‹ server_read

$tx->server_read($bytes);

Read data server-side β€” this is the one used to implement web servers such as Mojo::Server::Daemon.

πŸ¦‹ server_write

my $bytes = $tx->server_write;

Write data server-side β€” used to implement web servers such as Mojo::Server::Daemon. Matching set with client_write, we love symmetry. πŸŽ€


πŸ‘‘ SEE ALSO πŸ‘‘

Go read them, bestie, they're iconic.


okay that's the whole page, every last flag and method accounted for, no cap. Now go build something cute. πŸ’–

sign-off time: this beauty is perl v5.42.0, dated 2026-07-15, and yes the footer also calls it Mojo::T...on::HTTP(3) because the truncation never stops. mwah πŸ’‹ πŸ¦‹ ✨

πŸ“¦ where this page comes from