Name
SPVM::Mojo::Transaction::HTTP - HTTP transaction
Description
Mojo::Transaction::HTTP class in SPVM has methods to do someting.
Usage
use Mojo::Transaction::HTTP;
# Client
my $tx = Mojo::Transaction::HTTP->new;
$tx->req->set_method("GET");
$tx->req->url->parse("http://example.com");
$tx->req->headers->set_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->set_code(200);
$tx->res->headers->set_content_type("text/plain");
$tx->res->set_body("Hello World!");
Super Class
Events
request
Emitted when a request is ready and needs to be handled.
Callback:
method : void ($tx : Mojo::Transaction::HTTP);
Examples:
$tx->on(request => method : void ($tx : Mojo::Transaction::HTTP) {
});
resume
Emitted when transaction is resumed.
Callback:
method : void ($tx : Mojo::Transaction::HTTP);
Examples:
$tx->on(resume => method : void ($tx : Mojo::Transaction::HTTP) {
});
unexpected
Emitted for unexpected 1xx
responses that will be ignored.
Callback:
method : void ($tx : Mojo::Transaction::HTTP, $res : Mojo::Message::Response);
Examples:
$tx->on(unexpected => method : void ($tx : Mojo::Transaction::HTTP, $res : Mojo::Message::Response) {
});
Fields
has previous : rw Mojo::Transaction::HTTP;
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;
Class Methods
static method new : Mojo::Transaction::HTTP ();
Create a new Mojo::Transaction::HTTP object, and return it.
Instance Methods
client_read
method client_read : void ($chunk : string);
Read data client-side, used to implement user agents such as Mojo::UserAgent.
client_write
method client_write : string ($server : int);
Write data client-side, used to implement user agents such as Mojo::UserAgent.
is_empty
method is_empty : int ();
Check transaction for HEAD
request and 1xx
, 204
or 304
response.
keep_alive
method keep_alive : int ();
Check if connection can be kept alive.
redirects
method redirects : Mojo::Transaction::HTTP[] ();
Return an array reference with all previous transactions that preceded this follow-up transaction.
Examples:
# Paths of all previous requests
for my $_ (@{$tx->redirects}) {
say $_->req->url->path;
}
resume
method resume : void ();
Resume transaction.
server_read
method server_read : void ($chunk : string);
Read data server-side, used to implement web servers such as Mojo::Server::Daemon.
server_write
method server_write : string ($server : int);
Write data server-side, used to implement web servers such as Mojo::Server::Daemon.
See Also
Copyright & License
Copyright (c) 2025 Yuki Kimoto
MIT License