1Mojo::Message(3)      User Contributed Perl Documentation     Mojo::Message(3)
2
3
4

NAME

6       Mojo::Message - HTTP 1.1 Message Base Class
7

SYNOPSIS

9           use base 'Mojo::Message';
10

DESCRIPTION

12       Mojo::Message is an abstract base class for HTTP 1.1 messages as
13       described in RFC 2616 and RFC 2388.
14

ATTRIBUTES

16       Mojo::Message implements the following attributes.
17
18   "body_cb"
19           my $cb = $message->body_cb;
20
21           $counter = 1;
22           $message = $message->body_cb(sub {
23               my $self  = shift;
24               my $chunk = '';
25               $chunk    = "hello world!" if $counter == 1;
26               $chunk    = "hello world2!\n\n" if $counter == 2;
27               $counter++;
28               return $chunk;
29           });
30
31       Content generator callback.
32
33   "buffer"
34           my $buffer = $message->buffer;
35           $message   = $message->buffer(Mojo::ByteStream->new);
36
37       Input buffer for parsing.
38
39   "content"
40           my $content = $message->content;
41           $message    = $message->content(Mojo::Content::Single->new);
42
43       Content container, defaults to a Mojo::Content::Single object.
44
45   "default_charset"
46           my $charset = $message->default_charset;
47           $message    = $message->default_charset('UTF-8');
48
49       Default charset used for form data parsing.
50
51   "dom_class"
52           my $class = $message->dom_class;
53           $message  = $message->dom_class('Mojo::DOM');
54
55       Class to be used for DOM manipulation, defaults to Mojo::DOM.  Note
56       that this attribute is EXPERIMENTAL and might change without warning!
57
58   "finish_cb"
59           my $cb   = $message->finish_cb;
60           $message = $message->finish_cb(sub {
61               my $self = shift;
62           });
63
64       Callback called after message building or parsing is finished.
65
66   "json_class"
67           my $class = $message->json_class;
68           $message  = $message->json_class('Mojo::JSON');
69
70       Class to be used for JSON deserialization with "json", defaults to
71       Mojo::JSON.  Note that this attribute is EXPERIMENTAL and might change
72       without warning!
73
74   "major_version"
75           my $major_version = $message->major_version;
76           $message          = $message->major_version(1);
77
78       Major version, defaults to 1.
79
80   "minor_version"
81           my $minor_version = $message->minor_version;
82           $message          = $message->minor_version(1);
83
84       Minor version, defaults to 1.
85
86   "progress_cb"
87           my $cb   = $message->progress_cb;
88           $message = $message->progress_cb(sub {
89               my $self = shift;
90               print '+';
91           });
92
93       Progress callback.
94

METHODS

96       Mojo::Message inherits all methods from Mojo::Base and implements the
97       following new ones.
98
99   "at_least_version"
100           my $success = $message->at_least_version('1.1');
101
102       Check if message is at least a specific version.
103
104   "body"
105           my $string = $message->body;
106           $message   = $message->body('Hello!');
107
108           $counter = 1;
109           $message = $message->body(sub {
110               my $self  = shift;
111               my $chunk = '';
112               $chunk    = "hello world!" if $counter == 1;
113               $chunk    = "hello world2!\n\n" if $counter == 2;
114               $counter++;
115               return $chunk;
116           });
117
118       Helper for simplified content access.
119
120   "body_params"
121           my $params = $message->body_params;
122
123       "POST" parameters.
124
125   "body_size"
126           my $size = $message->body_size;
127
128       Size of the body in bytes.
129
130   "to_string"
131   "build"
132           my $string = $message->build;
133
134       Render whole message.
135
136   "build_body"
137           my $string = $message->build_body;
138
139       Render whole body.
140
141   "build_headers"
142           my $string = $message->build_headers;
143
144       Render all headers.
145
146   "build_start_line"
147           my $string = $message->build_start_line;
148
149       Render start line.
150
151   "cookie"
152           my $cookie  = $message->cookie('foo');
153           my @cookies = $message->cookie('foo');
154
155       Access message cookies.
156
157   "dom"
158           my $dom = $message->dom;
159
160       Parses content into a Mojo::DOM object.  Note that this method is
161       EXPERIMENTAL and might change without warning!
162
163   "error"
164           my $message          = $message->error;
165           my ($message, $code) = $message->error;
166           $message             = $message->error('Parser error.');
167           $message             = $message->error('Parser error.', 500);
168
169       Parser errors and codes.
170
171   "fix_headers"
172           $message = $message->fix_headers;
173
174       Make sure message has all required headers for the current HTTP
175       version.
176
177   "get_body_chunk"
178           my $string = $message->get_body_chunk($offset);
179
180       Get a chunk of body data starting from a specific position.
181
182   "get_header_chunk"
183           my $string = $message->get_header_chunk($offset);
184
185       Get a chunk of header data, starting from a specific position.
186
187   "get_start_line_chunk"
188           my $string = $message->get_start_line_chunk($offset);
189
190       Get a chunk of start line data starting from a specific position.
191
192   "has_leftovers"
193           my $leftovers = $message->has_leftovers;
194
195       CHeck if message parser has leftover data in the buffer.
196
197   "header_size"
198           my $size = $message->header_size;
199
200       Size of headers in bytes.
201
202   "headers"
203           my $headers = $message->headers;
204           $message    = $message->headers(Mojo::Headers->new);
205
206       Header container, defaults to a Mojo::Headers object.
207
208   "is_chunked"
209           my $chunked = $message->is_chunked;
210
211       Check if message content is chunked.
212
213   "is_done"
214           my $done = $message->is_done;
215
216       Check if parser is done.
217
218   "is_multipart"
219           my $multipart = $message->is_multipart;
220
221       Check if message content is multipart.
222
223   "json"
224           my $object = $message->json;
225           my $array  = $message->json;
226
227       Decode JSON message body directly using Mojo::JSON if possible, returns
228       "undef" otherwise.  Note that this method is EXPERIMENTAL and might
229       change without warning!
230
231   "leftovers"
232           my $bytes = $message->leftovers;
233
234       Remove leftover data from the parser buffer.
235
236   "param"
237           my $param  = $message->param('foo');
238           my @params = $message->param('foo');
239
240       Access "GET" and "POST" parameters.
241
242   "parse"
243           $message = $message->parse('HTTP/1.1 200 OK...');
244
245       Parse message chunk.
246
247   "parse_until_body"
248           $message = $message->parse_until_body('HTTP/1.1 200 OK...');
249
250       Parse message chunk until the body is reached.
251
252   "start_line_size"
253           my $size = $message->start_line_size;
254
255       Size of the start line in bytes.
256
257   "upload"
258           my $upload  = $message->upload('foo');
259           my @uploads = $message->upload('foo');
260
261       Access file uploads.
262
263   "uploads"
264           my $uploads = $message->uploads;
265
266       All file uploads.
267
268   "version"
269           my $version = $message->version;
270           $message    = $message->version('1.1');
271
272       HTTP version of message.
273

SEE ALSO

275       Mojolicious, Mojolicious::Guides, <http://mojolicious.org>.
276
277
278
279perl v5.12.3                      2010-08-17                  Mojo::Message(3)
Impressum