.\" Automatically generated by Pod::Man 4.11 (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::Message::Response 3"
.TH Mojo::Message::Response 3 "2023-03-08" "perl v5.26.3" "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::Message::Response \- HTTP response
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 1
\& use Mojo::Message::Response;
\&
\& # Parse
\& my $res = Mojo::Message::Response\->new;
\& $res\->parse("HTTP/1.0 200 OK\ex0d\ex0a");
\& $res\->parse("Content\-Length: 12\ex0d\ex0a");
\& $res\->parse("Content\-Type: text/plain\ex0d\ex0a\ex0d\ex0a");
\& $res\->parse(\*(AqHello World!\*(Aq);
\& say $res\->code;
\& say $res\->headers\->content_type;
\& say $res\->body;
\&
\& # Build
\& my $res = Mojo::Message::Response\->new;
\& $res\->code(200);
\& $res\->headers\->content_type(\*(Aqtext/plain\*(Aq);
\& $res\->body(\*(AqHello World!\*(Aq);
\& say $res\->to_string;
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
Mojo::Message::Response is a container for \s-1HTTP\s0 responses, based on \s-1RFC 7230\s0 <https://tools.ietf.org/html/rfc7230>
and \s-1RFC 7231\s0 <https://tools.ietf.org/html/rfc7231>.
.SH "EVENTS"
.IX Header "EVENTS"
Mojo::Message::Response inherits all events from Mojo::Message.
.SH "ATTRIBUTES"
.IX Header "ATTRIBUTES"
Mojo::Message::Response inherits all attributes from Mojo::Message and implements the following new ones.
.SS "code"
.IX Subsection "code"
.Vb 2
\& my $code = $res\->code;
\& $res = $res\->code(200);
.Ve
.PP
\&\s-1HTTP\s0 response status code.
.SS "max_message_size"
.IX Subsection "max_message_size"
.Vb 2
\& my $size = $res\->max_message_size;
\& $res = $res\->max_message_size(1024);
.Ve
.PP
Maximum message size in bytes, defaults to the value of the \f(CW\*(C`MOJO_MAX_MESSAGE_SIZE\*(C'\fR environment variable or
\&\f(CW2147483648\fR (2GiB). Setting the value to \f(CW0\fR will allow messages of indefinite size.
.SS "message"
.IX Subsection "message"
.Vb 2
\& my $msg = $res\->message;
\& $res = $res\->message(\*(AqOK\*(Aq);
.Ve
.PP
\&\s-1HTTP\s0 response status message.
.SH "METHODS"
.IX Header "METHODS"
Mojo::Message::Response inherits all methods from Mojo::Message and implements the following new ones.
.SS "cookies"
.IX Subsection "cookies"
.Vb 3
\& my $cookies = $res\->cookies;
\& $res = $res\->cookies(Mojo::Cookie::Response\->new);
\& $res = $res\->cookies({name => \*(Aqfoo\*(Aq, value => \*(Aqbar\*(Aq});
.Ve
.PP
Access response cookies, usually Mojo::Cookie::Response objects.
.PP
.Vb 2
\& # Names of all cookies
\& say $_\->name for @{$res\->cookies};
.Ve
.SS "default_message"
.IX Subsection "default_message"
.Vb 2
\& my $msg = $res\->default_message;
\& my $msg = $res\->default_message(418);
.Ve
.PP
Generate default response message for status code, defaults to using \*(L"code\*(R".
.SS "extract_start_line"
.IX Subsection "extract_start_line"
.Vb 1
\& my $bool = $res\->extract_start_line(\e$str);
.Ve
.PP
Extract status-line from string.
.SS "fix_headers"
.IX Subsection "fix_headers"
.Vb 1
\& $res = $res\->fix_headers;
.Ve
.PP
Make sure response has all required headers.
.SS "get_start_line_chunk"
.IX Subsection "get_start_line_chunk"
.Vb 1
\& my $bytes = $res\->get_start_line_chunk($offset);
.Ve
.PP
Get a chunk of status-line data starting from a specific position. Note that this method finalizes the response.
.SS "is_client_error"
.IX Subsection "is_client_error"
.Vb 1
\& my $bool = $res\->is_client_error;
.Ve
.PP
Check if this response has a \f(CW\*(C`4xx\*(C'\fR status \*(L"code\*(R".
.SS "is_empty"
.IX Subsection "is_empty"
.Vb 1
\& my $bool = $res\->is_empty;
.Ve
.PP
Check if this response has a \f(CW\*(C`1xx\*(C'\fR, \f(CW204\fR or \f(CW304\fR status \*(L"code\*(R".
.SS "is_error"
.IX Subsection "is_error"
.Vb 1
\& my $bool = $res\->is_error;
.Ve
.PP
Check if this response has a \f(CW\*(C`4xx\*(C'\fR or \f(CW\*(C`5xx\*(C'\fR status \*(L"code\*(R".
.SS "is_info"
.IX Subsection "is_info"
.Vb 1
\& my $bool = $res\->is_info;
.Ve
.PP
Check if this response has a \f(CW\*(C`1xx\*(C'\fR status \*(L"code\*(R".
.SS "is_redirect"
.IX Subsection "is_redirect"
.Vb 1
\& my $bool = $res\->is_redirect;
.Ve
.PP
Check if this response has a \f(CW\*(C`3xx\*(C'\fR status \*(L"code\*(R".
.SS "is_server_error"
.IX Subsection "is_server_error"
.Vb 1
\& my $bool = $res\->is_server_error;
.Ve
.PP
Check if this response has a \f(CW\*(C`5xx\*(C'\fR status \*(L"code\*(R".
.SS "is_success"
.IX Subsection "is_success"
.Vb 1
\& my $bool = $res\->is_success;
.Ve
.PP
Check if this response has a \f(CW\*(C`2xx\*(C'\fR status \*(L"code\*(R".
.SS "start_line_size"
.IX Subsection "start_line_size"
.Vb 1
\& my $size = $req\->start_line_size;
.Ve
.PP
Size of the status-line in bytes. Note that this method finalizes the response.
.SH "SEE ALSO"
.IX Header "SEE ALSO"
Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.