.\" Automatically generated by Pod::Man 4.10 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Mojo::Transaction::HTTP 3pm" .TH Mojo::Transaction::HTTP 3pm "2019-02-05" "perl v5.28.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Mojo::Transaction::HTTP \- HTTP transaction .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Mojo::Transaction::HTTP; \& \& # Client \& my $tx = Mojo::Transaction::HTTP\->new; \& $tx\->req\->method(\*(AqGET\*(Aq); \& $tx\->req\->url\->parse(\*(Aqhttp://example.com\*(Aq); \& $tx\->req\->headers\->accept(\*(Aqapplication/json\*(Aq); \& 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(\*(Aqtext/plain\*(Aq); \& $tx\->res\->body(\*(AqHello World!\*(Aq); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Mojo::Transaction::HTTP is a container for \s-1HTTP\s0 transactions, based on \&\s-1RFC 7230\s0 and \&\s-1RFC 7231\s0 . .SH "EVENTS" .IX Header "EVENTS" Mojo::Transaction::HTTP inherits all events from Mojo::Transaction and can emit the following new ones. .SS "request" .IX Subsection "request" .Vb 4 \& $tx\->on(request => sub { \& my $tx = shift; \& ... \& }); .Ve .PP Emitted when a request is ready and needs to be handled. .PP .Vb 4 \& $tx\->on(request => sub { \& my $tx = shift; \& $tx\->res\->headers\->header(\*(AqX\-Bender\*(Aq => \*(AqBite my shiny metal ass!\*(Aq); \& }); .Ve .SS "resume" .IX Subsection "resume" .Vb 4 \& $tx\->on(resume => sub { \& my $tx = shift; \& ... \& }); .Ve .PP Emitted when transaction is resumed. .SS "unexpected" .IX Subsection "unexpected" .Vb 4 \& $tx\->on(unexpected => sub { \& my ($tx, $res) = @_; \& ... \& }); .Ve .PP Emitted for unexpected \f(CW\*(C`1xx\*(C'\fR responses that will be ignored. .PP .Vb 4 \& $tx\->on(unexpected => sub { \& my $tx = shift; \& $tx\->res\->on(finish => sub { say \*(AqFollow\-up response is finished.\*(Aq }); \& }); .Ve .SH "ATTRIBUTES" .IX Header "ATTRIBUTES" Mojo::Transaction::HTTP inherits all attributes from Mojo::Transaction and implements the following new ones. .SS "previous" .IX Subsection "previous" .Vb 2 \& my $previous = $tx\->previous; \& $tx = $tx\->previous(Mojo::Transaction::HTTP\->new); .Ve .PP Previous transaction that triggered this follow-up transaction, usually a Mojo::Transaction::HTTP object. .PP .Vb 3 \& # Paths of previous requests \& say $tx\->previous\->previous\->req\->url\->path; \& say $tx\->previous\->req\->url\->path; .Ve .SH "METHODS" .IX Header "METHODS" Mojo::Transaction::HTTP inherits all methods from Mojo::Transaction and implements the following new ones. .SS "client_read" .IX Subsection "client_read" .Vb 1 \& $tx\->client_read($bytes); .Ve .PP Read data client-side, used to implement user agents such as Mojo::UserAgent. .SS "client_write" .IX Subsection "client_write" .Vb 1 \& my $bytes = $tx\->client_write; .Ve .PP Write data client-side, used to implement user agents such as Mojo::UserAgent. .SS "is_empty" .IX Subsection "is_empty" .Vb 1 \& my $bool = $tx\->is_empty; .Ve .PP Check transaction for \f(CW\*(C`HEAD\*(C'\fR request and \f(CW\*(C`1xx\*(C'\fR, \f(CW204\fR or \f(CW304\fR response. .SS "keep_alive" .IX Subsection "keep_alive" .Vb 1 \& my $bool = $tx\->keep_alive; .Ve .PP Check if connection can be kept alive. .SS "redirects" .IX Subsection "redirects" .Vb 1 \& my $redirects = $tx\->redirects; .Ve .PP Return an array reference with all previous transactions that preceded this follow-up transaction. .PP .Vb 2 \& # Paths of all previous requests \& say $_\->req\->url\->path for @{$tx\->redirects}; .Ve .SS "resume" .IX Subsection "resume" .Vb 1 \& $tx = $tx\->resume; .Ve .PP Resume transaction. .SS "server_read" .IX Subsection "server_read" .Vb 1 \& $tx\->server_read($bytes); .Ve .PP Read data server-side, used to implement web servers such as Mojo::Server::Daemon. .SS "server_write" .IX Subsection "server_write" .Vb 1 \& my $bytes = $tx\->server_write; .Ve .PP Write data server-side, used to implement web servers such as Mojo::Server::Daemon. .SH "SEE ALSO" .IX Header "SEE ALSO" Mojolicious, Mojolicious::Guides, .