.\" Automatically generated by Pod::Man 2.25 (Pod::Simple 3.16) .\" .\" 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" '' '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 turned on, 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. .ie \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .el \{\ . de IX .. .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Mojo::Message 3pm" .TH Mojo::Message 3pm "2012-09-05" "perl v5.14.2" "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 \- HTTP 1.1 message base class .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Mojo::Base \*(AqMojo::Message\*(Aq; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Mojo::Message is an abstract base class for \s-1HTTP\s0 1.1 messages as described in \s-1RFC\s0 2616 and \s-1RFC\s0 2388. .SH "EVENTS" .IX Header "EVENTS" Mojo::Message can emit the following events. .ie n .SS """finish""" .el .SS "\f(CWfinish\fP" .IX Subsection "finish" .Vb 4 \& $message\->on(finish => sub { \& my $message = shift; \& ... \& }); .Ve .PP Emitted after message building or parsing is finished. .PP .Vb 5 \& my $before = time; \& $message\->on(finish => sub { \& my $message = shift; \& $message\->headers\->header(\*(AqX\-Parser\-Time\*(Aq => time \- $before); \& }); .Ve .ie n .SS """progress""" .el .SS "\f(CWprogress\fP" .IX Subsection "progress" .Vb 4 \& $message\->on(progress => sub { \& my $message = shift; \& ... \& }); .Ve .PP Emitted when message building or parsing makes progress. .PP .Vb 5 \& # Building \& $message\->on(progress => sub { \& my ($message, $state, $offset) = @_; \& say qq{Building "$state" at offset $offset}; \& }); \& \& # Parsing \& $message\->on(progress => sub { \& my $message = shift; \& return unless my $len = $message\->headers\->content_length; \& my $size = $message\->content\->progress; \& say \*(AqProgress: \*(Aq, $size == $len ? 100 : int($size / ($len / 100)), \*(Aq%\*(Aq; \& }); .Ve .SH "ATTRIBUTES" .IX Header "ATTRIBUTES" Mojo::Message implements the following attributes. .ie n .SS """content""" .el .SS "\f(CWcontent\fP" .IX Subsection "content" .Vb 2 \& my $message = $message\->content; \& $message = $message\->content(Mojo::Content::Single\->new); .Ve .PP Content container, defaults to a Mojo::Content::Single object. .ie n .SS """default_charset""" .el .SS "\f(CWdefault_charset\fP" .IX Subsection "default_charset" .Vb 2 \& my $charset = $message\->default_charset; \& $message = $message\->default_charset(\*(AqUTF\-8\*(Aq); .Ve .PP Default charset used for form data parsing, defaults to \f(CW\*(C`UTF\-8\*(C'\fR. .ie n .SS """dom_class""" .el .SS "\f(CWdom_class\fP" .IX Subsection "dom_class" .Vb 2 \& my $class = $message\->dom_class; \& $message = $message\->dom_class(\*(AqMojo::DOM\*(Aq); .Ve .PP Class to be used for \s-1DOM\s0 manipulation with the \f(CW\*(C`dom\*(C'\fR method, defaults to Mojo::DOM. .ie n .SS """json_class""" .el .SS "\f(CWjson_class\fP" .IX Subsection "json_class" .Vb 2 \& my $class = $message\->json_class; \& $message = $message\->json_class(\*(AqMojo::JSON\*(Aq); .Ve .PP Class to be used for \s-1JSON\s0 deserialization with the \f(CW\*(C`json\*(C'\fR method, defaults to Mojo::JSON. .ie n .SS """max_message_size""" .el .SS "\f(CWmax_message_size\fP" .IX Subsection "max_message_size" .Vb 2 \& my $size = $message\->max_message_size; \& $message = $message\->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(CW5242880\fR. Note that increasing this value can also drastically increase memory usage, should you for example attempt to parse an excessively large message body with the \&\f(CW\*(C`body_params\*(C'\fR, \f(CW\*(C`dom\*(C'\fR or \f(CW\*(C`json\*(C'\fR methods. .ie n .SS """version""" .el .SS "\f(CWversion\fP" .IX Subsection "version" .Vb 2 \& my $version = $message\->version; \& $message = $message\->version(\*(Aq1.1\*(Aq); .Ve .PP \&\s-1HTTP\s0 version of message. .SH "METHODS" .IX Header "METHODS" Mojo::Message inherits all methods from Mojo::EventEmitter and implements the following new ones. .ie n .SS """at_least_version""" .el .SS "\f(CWat_least_version\fP" .IX Subsection "at_least_version" .Vb 1 \& my $success = $message\->at_least_version(\*(Aq1.1\*(Aq); .Ve .PP Check if message is at least a specific version. .ie n .SS """body""" .el .SS "\f(CWbody\fP" .IX Subsection "body" .Vb 3 \& my $string = $message\->body; \& $message = $message\->body(\*(AqHello!\*(Aq); \& my $cb = $message\->body(sub {...}); .Ve .PP Access \f(CW\*(C`content\*(C'\fR data or replace all subscribers of the \f(CW\*(C`read\*(C'\fR event. .PP .Vb 4 \& $message\->body(sub { \& my ($message, $chunk) = @_; \& say "Streaming: $chunk"; \& }); .Ve .ie n .SS """body_params""" .el .SS "\f(CWbody_params\fP" .IX Subsection "body_params" .Vb 1 \& my $p = $message\->body_params; .Ve .PP \&\f(CW\*(C`POST\*(C'\fR parameters extracted from \f(CW\*(C`x\-application\-urlencoded\*(C'\fR, \&\f(CW\*(C`application/x\-www\-form\-urlencoded\*(C'\fR or \f(CW\*(C`multipart/form\-data\*(C'\fR message body, usually a Mojo::Parameters object. Note that this method caches all data, so it should not be called before the entire message body has been received. .PP .Vb 1 \& say $message\->body_params\->param(\*(Aqfoo\*(Aq); .Ve .ie n .SS """body_size""" .el .SS "\f(CWbody_size\fP" .IX Subsection "body_size" .Vb 1 \& my $size = $message\->body_size; .Ve .PP Alias for \*(L"body_size\*(R" in Mojo::Content. .ie n .SS """build_body""" .el .SS "\f(CWbuild_body\fP" .IX Subsection "build_body" .Vb 1 \& my $string = $message\->build_body; .Ve .PP Render whole body. .ie n .SS """build_headers""" .el .SS "\f(CWbuild_headers\fP" .IX Subsection "build_headers" .Vb 1 \& my $string = $message\->build_headers; .Ve .PP Render all headers. .ie n .SS """build_start_line""" .el .SS "\f(CWbuild_start_line\fP" .IX Subsection "build_start_line" .Vb 1 \& my $string = $message\->build_start_line; .Ve .PP Render start line. .ie n .SS """cookie""" .el .SS "\f(CWcookie\fP" .IX Subsection "cookie" .Vb 2 \& my $cookie = $message\->cookie(\*(Aqfoo\*(Aq); \& my @cookies = $message\->cookie(\*(Aqfoo\*(Aq); .Ve .PP Access message cookies, usually Mojo::Cookie::Request or Mojo::Cookie::Response objects. Note that this method caches all data, so it should not be called before all headers have been received. .PP .Vb 1 \& say $message\->cookie(\*(Aqfoo\*(Aq)\->value; .Ve .ie n .SS """cookies""" .el .SS "\f(CWcookies\fP" .IX Subsection "cookies" .Vb 1 \& my $cookies = $message\->cookies; .Ve .PP Access message cookies, meant to be overloaded in a subclass. .ie n .SS """dom""" .el .SS "\f(CWdom\fP" .IX Subsection "dom" .Vb 2 \& my $dom = $message\->dom; \& my $collection = $message\->dom(\*(Aqa[href]\*(Aq); .Ve .PP Turns message body into a Mojo::DOM object and takes an optional selector to perform a \f(CW\*(C`find\*(C'\fR on it right away, which returns a collection. .PP .Vb 2 \& # Perform "find" right away \& $message\->dom(\*(Aqh1, h2, h3\*(Aq)\->each(sub { say $_\->text }); \& \& # Use everything else Mojo::DOM has to offer \& say $message\->dom\->at(\*(Aqtitle\*(Aq)\->text; \& $message\->dom\->html\->body\->children\->each(sub { say $_\->type }); .Ve .ie n .SS """error""" .el .SS "\f(CWerror\fP" .IX Subsection "error" .Vb 4 \& my $message = $message\->error; \& my ($message, $code) = $message\->error; \& $message = $message\->error(\*(AqParser error.\*(Aq); \& $message = $message\->error(\*(AqParser error.\*(Aq, 500); .Ve .PP Parser errors and codes. .ie n .SS """fix_headers""" .el .SS "\f(CWfix_headers\fP" .IX Subsection "fix_headers" .Vb 1 \& $message = $message\->fix_headers; .Ve .PP Make sure message has all required headers for the current \s-1HTTP\s0 version. .ie n .SS """get_body_chunk""" .el .SS "\f(CWget_body_chunk\fP" .IX Subsection "get_body_chunk" .Vb 1 \& my $string = $message\->get_body_chunk($offset); .Ve .PP Get a chunk of body data starting from a specific position. .ie n .SS """get_header_chunk""" .el .SS "\f(CWget_header_chunk\fP" .IX Subsection "get_header_chunk" .Vb 1 \& my $string = $message\->get_header_chunk($offset); .Ve .PP Get a chunk of header data, starting from a specific position. .ie n .SS """get_start_line_chunk""" .el .SS "\f(CWget_start_line_chunk\fP" .IX Subsection "get_start_line_chunk" .Vb 1 \& my $string = $message\->get_start_line_chunk($offset); .Ve .PP Get a chunk of start line data starting from a specific position. .ie n .SS """has_leftovers""" .el .SS "\f(CWhas_leftovers\fP" .IX Subsection "has_leftovers" .Vb 1 \& my $success = $message\->has_leftovers; .Ve .PP Alias for \*(L"has_leftovers\*(R" in Mojo::Content. .ie n .SS """header_size""" .el .SS "\f(CWheader_size\fP" .IX Subsection "header_size" .Vb 1 \& my $size = $message\->header_size; .Ve .PP Size of headers in bytes. .ie n .SS """headers""" .el .SS "\f(CWheaders\fP" .IX Subsection "headers" .Vb 1 \& my $headers = $message\->headers; .Ve .PP Alias for \*(L"headers\*(R" in Mojo::Content. .PP .Vb 1 \& say $message\->headers\->content_type; .Ve .ie n .SS """is_chunked""" .el .SS "\f(CWis_chunked\fP" .IX Subsection "is_chunked" .Vb 1 \& my $success = $message\->is_chunked; .Ve .PP Alias for \*(L"is_chunked\*(R" in Mojo::Content. .ie n .SS """is_dynamic""" .el .SS "\f(CWis_dynamic\fP" .IX Subsection "is_dynamic" .Vb 1 \& my $success = $message\->is_dynamic; .Ve .PP Alias for \*(L"is_dynamic\*(R" in Mojo::Content. .ie n .SS """is_finished""" .el .SS "\f(CWis_finished\fP" .IX Subsection "is_finished" .Vb 1 \& my $success = $message\->is_finished; .Ve .PP Check if parser is finished. .ie n .SS """is_limit_exceeded""" .el .SS "\f(CWis_limit_exceeded\fP" .IX Subsection "is_limit_exceeded" .Vb 1 \& my $success = $message\->is_limit_exceeded; .Ve .PP Check if message has exceeded \f(CW\*(C`max_line_size\*(C'\fR or \f(CW\*(C`max_message_size\*(C'\fR. .ie n .SS """is_multipart""" .el .SS "\f(CWis_multipart\fP" .IX Subsection "is_multipart" .Vb 1 \& my $success = $message\->is_multipart; .Ve .PP Alias for \*(L"is_multipart\*(R" in Mojo::Content. .ie n .SS """json""" .el .SS "\f(CWjson\fP" .IX Subsection "json" .Vb 3 \& my $hash = $message\->json; \& my $array = $message\->json; \& my $value = $message\->json(\*(Aq/foo/bar\*(Aq); .Ve .PP Decode \s-1JSON\s0 message body directly using Mojo::JSON if possible, returns \&\f(CW\*(C`undef\*(C'\fR otherwise. An optional \s-1JSON\s0 Pointer can be used to extract a specific value with Mojo::JSON::Pointer. .PP .Vb 2 \& say $message\->json\->{foo}{bar}[23]; \& say $message\->json(\*(Aq/foo/bar/23\*(Aq); .Ve .ie n .SS """leftovers""" .el .SS "\f(CWleftovers\fP" .IX Subsection "leftovers" .Vb 1 \& my $bytes = $message\->leftovers; .Ve .PP Alias for \*(L"leftovers\*(R" in Mojo::Content. .ie n .SS """max_line_size""" .el .SS "\f(CWmax_line_size\fP" .IX Subsection "max_line_size" .Vb 1 \& $message\->max_line_size(1024); .Ve .PP Alias for \*(L"max_line_size\*(R" in Mojo::Headers. .ie n .SS """param""" .el .SS "\f(CWparam\fP" .IX Subsection "param" .Vb 3 \& my @names = $message\->param; \& my $foo = $message\->param(\*(Aqfoo\*(Aq); \& my @foo = $message\->param(\*(Aqfoo\*(Aq); .Ve .PP Access \f(CW\*(C`POST\*(C'\fR parameters. Note that this method caches all data, so it should not be called before the entire message body has been received. .ie n .SS """parse""" .el .SS "\f(CWparse\fP" .IX Subsection "parse" .Vb 1 \& $message = $message\->parse(\*(AqHTTP/1.1 200 OK...\*(Aq); .Ve .PP Parse message chunk. .ie n .SS """parse_until_body""" .el .SS "\f(CWparse_until_body\fP" .IX Subsection "parse_until_body" .Vb 1 \& $message = $message\->parse_until_body(\*(AqHTTP/1.1 200 OK...\*(Aq); .Ve .PP Parse message chunk until the body is reached. .ie n .SS """start_line_size""" .el .SS "\f(CWstart_line_size\fP" .IX Subsection "start_line_size" .Vb 1 \& my $size = $message\->start_line_size; .Ve .PP Size of the start line in bytes. .ie n .SS """to_string""" .el .SS "\f(CWto_string\fP" .IX Subsection "to_string" .Vb 1 \& my $string = $message\->to_string; .Ve .PP Render whole message. .ie n .SS """upload""" .el .SS "\f(CWupload\fP" .IX Subsection "upload" .Vb 2 \& my $upload = $message\->upload(\*(Aqfoo\*(Aq); \& my @uploads = $message\->upload(\*(Aqfoo\*(Aq); .Ve .PP Access \f(CW\*(C`multipart/form\-data\*(C'\fR file uploads, usually Mojo::Upload objects. Note that this method caches all data, so it should not be called before the entire message body has been received. .PP .Vb 1 \& say $message\->upload(\*(Aqfoo\*(Aq)\->asset\->slurp; .Ve .ie n .SS """uploads""" .el .SS "\f(CWuploads\fP" .IX Subsection "uploads" .Vb 1 \& my $uploads = $message\->uploads; .Ve .PP All \f(CW\*(C`multipart/form\-data\*(C'\fR file uploads, usually Mojo::Upload objects. .PP .Vb 1 \& say $message\->uploads\->[2]\->filename; .Ve .ie n .SS """write""" .el .SS "\f(CWwrite\fP" .IX Subsection "write" .Vb 2 \& $message\->write(\*(AqHello!\*(Aq); \& $message\->write(\*(AqHello!\*(Aq, sub {...}); .Ve .PP Alias for \*(L"write\*(R" in Mojo::Content. .ie n .SS """write_chunk""" .el .SS "\f(CWwrite_chunk\fP" .IX Subsection "write_chunk" .Vb 2 \& $message\->write_chunk(\*(AqHello!\*(Aq); \& $message\->write_chunk(\*(AqHello!\*(Aq, sub {...}); .Ve .PP Alias for \*(L"write_headers\*(R" in Mojo::Content. .SH "SEE ALSO" .IX Header "SEE ALSO" Mojolicious, Mojolicious::Guides, .