1Mojo::Message::ResponseU(s3e)r Contributed Perl DocumentaMtoijoon::Message::Response(3)
2
3
4

NAME

6       Mojo::Message::Response - HTTP response
7

SYNOPSIS

9         use Mojo::Message::Response;
10
11         # Parse
12         my $res = Mojo::Message::Response->new;
13         $res->parse("HTTP/1.0 200 OK\x0d\x0a");
14         $res->parse("Content-Length: 12\x0d\x0a");
15         $res->parse("Content-Type: text/plain\x0d\x0a\x0d\x0a");
16         $res->parse('Hello World!');
17         say $res->code;
18         say $res->headers->content_type;
19         say $res->body;
20
21         # Build
22         my $res = Mojo::Message::Response->new;
23         $res->code(200);
24         $res->headers->content_type('text/plain');
25         $res->body('Hello World!');
26         say $res->to_string;
27

DESCRIPTION

29       Mojo::Message::Response is a container for HTTP responses, based on RFC
30       7230 <http://tools.ietf.org/html/rfc7230> and RFC 7231
31       <http://tools.ietf.org/html/rfc7231>.
32

EVENTS

34       Mojo::Message::Response inherits all events from Mojo::Message.
35

ATTRIBUTES

37       Mojo::Message::Response inherits all attributes from Mojo::Message and
38       implements the following new ones.
39
40   code
41         my $code = $res->code;
42         $res     = $res->code(200);
43
44       HTTP response status code.
45
46   max_message_size
47         my $size = $res->max_message_size;
48         $res     = $res->max_message_size(1024);
49
50       Maximum message size in bytes, defaults to the value of the
51       "MOJO_MAX_MESSAGE_SIZE" environment variable or 2147483648 (2GiB).
52       Setting the value to 0 will allow messages of indefinite size.
53
54   message
55         my $msg = $res->message;
56         $res    = $res->message('OK');
57
58       HTTP response status message.
59

METHODS

61       Mojo::Message::Response inherits all methods from Mojo::Message and
62       implements the following new ones.
63
64   cookies
65         my $cookies = $res->cookies;
66         $res        = $res->cookies(Mojo::Cookie::Response->new);
67         $res        = $res->cookies({name => 'foo', value => 'bar'});
68
69       Access response cookies, usually Mojo::Cookie::Response objects.
70
71         # Names of all cookies
72         say $_->name for @{$res->cookies};
73
74   default_message
75         my $msg = $res->default_message;
76         my $msg = $res->default_message(418);
77
78       Generate default response message for status code, defaults to using
79       "code".
80
81   extract_start_line
82         my $bool = $res->extract_start_line(\$str);
83
84       Extract status-line from string.
85
86   fix_headers
87         $res = $res->fix_headers;
88
89       Make sure response has all required headers.
90
91   get_start_line_chunk
92         my $bytes = $res->get_start_line_chunk($offset);
93
94       Get a chunk of status-line data starting from a specific position. Note
95       that this method finalizes the response.
96
97   is_client_error
98         my $bool = $res->is_client_error;
99
100       Check if this response has a "4xx" status "code".
101
102   is_empty
103         my $bool = $res->is_empty;
104
105       Check if this response has a "1xx", 204 or 304 status "code".
106
107   is_error
108         my $bool = $res->is_error;
109
110       Check if this response has a "4xx" or "5xx" status "code".
111
112   is_info
113         my $bool = $res->is_info;
114
115       Check if this response has a "1xx" status "code".
116
117   is_redirect
118         my $bool = $res->is_redirect;
119
120       Check if this response has a "3xx" status "code".
121
122   is_server_error
123         my $bool = $res->is_server_error;
124
125       Check if this response has a "5xx" status "code".
126
127   is_success
128         my $bool = $res->is_success;
129
130       Check if this response has a "2xx" status "code".
131
132   start_line_size
133         my $size = $req->start_line_size;
134
135       Size of the status-line in bytes. Note that this method finalizes the
136       response.
137

SEE ALSO

139       Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.
140
141
142
143perl v5.32.0                      2020-07-28        Mojo::Message::Response(3)
Impressum