.\" 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::Content 3pm" .TH Mojo::Content 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::Content \- HTTP content base class .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& package Mojo::Content::MyContent; \& use Mojo::Base \*(AqMojo::Content\*(Aq; \& \& sub body_contains {...} \& sub body_size {...} \& sub get_body_chunk {...} .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Mojo::Content is an abstract base class for \s-1HTTP\s0 content containers, based on \&\s-1RFC 7230\s0 and \&\s-1RFC 7231\s0 , like Mojo::Content::MultiPart and Mojo::Content::Single. .SH "EVENTS" .IX Header "EVENTS" Mojo::Content inherits all events from Mojo::EventEmitter and can emit the following new ones. .SS "body" .IX Subsection "body" .Vb 4 \& $content\->on(body => sub { \& my $content = shift; \& ... \& }); .Ve .PP Emitted once all headers have been parsed and the body starts. .PP .Vb 4 \& $content\->on(body => sub { \& my $content = shift; \& $content\->auto_upgrade(0) if $content\->headers\->header(\*(AqX\-No\-MultiPart\*(Aq); \& }); .Ve .SS "drain" .IX Subsection "drain" .Vb 4 \& $content\->on(drain => sub { \& my ($content, $offset) = @_; \& ... \& }); .Ve .PP Emitted once all data has been written. .PP .Vb 4 \& $content\->on(drain => sub { \& my $content = shift; \& $content\->write_chunk(time); \& }); .Ve .SS "read" .IX Subsection "read" .Vb 4 \& $content\->on(read => sub { \& my ($content, $bytes) = @_; \& ... \& }); .Ve .PP Emitted when a new chunk of content arrives. .PP .Vb 4 \& $content\->on(read => sub { \& my ($content, $bytes) = @_; \& say "Streaming: $bytes"; \& }); .Ve .SH "ATTRIBUTES" .IX Header "ATTRIBUTES" Mojo::Content implements the following attributes. .SS "auto_decompress" .IX Subsection "auto_decompress" .Vb 2 \& my $bool = $content\->auto_decompress; \& $content = $content\->auto_decompress($bool); .Ve .PP Decompress content automatically if \*(L"is_compressed\*(R" is true. .SS "auto_relax" .IX Subsection "auto_relax" .Vb 2 \& my $bool = $content\->auto_relax; \& $content = $content\->auto_relax($bool); .Ve .PP Try to detect when relaxed parsing is necessary. .SS "headers" .IX Subsection "headers" .Vb 2 \& my $headers = $content\->headers; \& $content = $content\->headers(Mojo::Headers\->new); .Ve .PP Content headers, defaults to a Mojo::Headers object. .SS "max_buffer_size" .IX Subsection "max_buffer_size" .Vb 2 \& my $size = $content\->max_buffer_size; \& $content = $content\->max_buffer_size(1024); .Ve .PP Maximum size in bytes of buffer for content parser, defaults to the value of the \f(CW\*(C`MOJO_MAX_BUFFER_SIZE\*(C'\fR environment variable or \f(CW262144\fR (256KiB). .SS "max_leftover_size" .IX Subsection "max_leftover_size" .Vb 2 \& my $size = $content\->max_leftover_size; \& $content = $content\->max_leftover_size(1024); .Ve .PP Maximum size in bytes of buffer for pipelined \s-1HTTP\s0 requests, defaults to the value of the \f(CW\*(C`MOJO_MAX_LEFTOVER_SIZE\*(C'\fR environment variable or \f(CW262144\fR (256KiB). .SS "relaxed" .IX Subsection "relaxed" .Vb 2 \& my $bool = $content\->relaxed; \& $content = $content\->relaxed($bool); .Ve .PP Activate relaxed parsing for responses that are terminated with a connection close. .SS "skip_body" .IX Subsection "skip_body" .Vb 2 \& my $bool = $content\->skip_body; \& $content = $content\->skip_body($bool); .Ve .PP Skip body parsing and finish after headers. .SH "METHODS" .IX Header "METHODS" Mojo::Content inherits all methods from Mojo::EventEmitter and implements the following new ones. .SS "body_contains" .IX Subsection "body_contains" .Vb 1 \& my $bool = $content\->body_contains(\*(Aqfoo bar baz\*(Aq); .Ve .PP Check if content contains a specific string. Meant to be overloaded in a subclass. .SS "body_size" .IX Subsection "body_size" .Vb 1 \& my $size = $content\->body_size; .Ve .PP Content size in bytes. Meant to be overloaded in a subclass. .SS "boundary" .IX Subsection "boundary" .Vb 1 \& my $boundary = $content\->boundary; .Ve .PP Extract multipart boundary from \f(CW\*(C`Content\-Type\*(C'\fR header. .SS "charset" .IX Subsection "charset" .Vb 1 \& my $charset = $content\->charset; .Ve .PP Extract charset from \f(CW\*(C`Content\-Type\*(C'\fR header. .SS "clone" .IX Subsection "clone" .Vb 1 \& my $clone = $content\->clone; .Ve .PP Return a new Mojo::Content object cloned from this content if possible, otherwise return \f(CW\*(C`undef\*(C'\fR. .SS "generate_body_chunk" .IX Subsection "generate_body_chunk" .Vb 1 \& my $bytes = $content\->generate_body_chunk(0); .Ve .PP Generate dynamic content. .SS "get_body_chunk" .IX Subsection "get_body_chunk" .Vb 1 \& my $bytes = $content\->get_body_chunk(0); .Ve .PP Get a chunk of content starting from a specific position. Meant to be overloaded in a subclass. .SS "get_header_chunk" .IX Subsection "get_header_chunk" .Vb 1 \& my $bytes = $content\->get_header_chunk(13); .Ve .PP Get a chunk of the headers starting from a specific position. Note that this method finalizes the content. .SS "header_size" .IX Subsection "header_size" .Vb 1 \& my $size = $content\->header_size; .Ve .PP Size of headers in bytes. Note that this method finalizes the content. .SS "headers_contain" .IX Subsection "headers_contain" .Vb 1 \& my $bool = $content\->headers_contain(\*(Aqfoo bar baz\*(Aq); .Ve .PP Check if headers contain a specific string. Note that this method finalizes the content. .SS "is_chunked" .IX Subsection "is_chunked" .Vb 1 \& my $bool = $content\->is_chunked; .Ve .PP Check if \f(CW\*(C`Transfer\-Encoding\*(C'\fR header indicates chunked transfer encoding. .SS "is_compressed" .IX Subsection "is_compressed" .Vb 1 \& my $bool = $content\->is_compressed; .Ve .PP Check \f(CW\*(C`Content\-Encoding\*(C'\fR header for \f(CW\*(C`gzip\*(C'\fR value. .SS "is_dynamic" .IX Subsection "is_dynamic" .Vb 1 \& my $bool = $content\->is_dynamic; .Ve .PP Check if content will be dynamically generated, which prevents \*(L"clone\*(R" from working. .SS "is_finished" .IX Subsection "is_finished" .Vb 1 \& my $bool = $content\->is_finished; .Ve .PP Check if parser is finished. .SS "is_limit_exceeded" .IX Subsection "is_limit_exceeded" .Vb 1 \& my $bool = $content\->is_limit_exceeded; .Ve .PP Check if buffer has exceeded \*(L"max_buffer_size\*(R". .SS "is_multipart" .IX Subsection "is_multipart" .Vb 1 \& my $bool = $content\->is_multipart; .Ve .PP False, this is not a Mojo::Content::MultiPart object. .SS "is_parsing_body" .IX Subsection "is_parsing_body" .Vb 1 \& my $bool = $content\->is_parsing_body; .Ve .PP Check if body parsing started yet. .SS "leftovers" .IX Subsection "leftovers" .Vb 1 \& my $bytes = $content\->leftovers; .Ve .PP Get leftover data from content parser. .SS "parse" .IX Subsection "parse" .Vb 2 \& $content \& = $content\->parse("Content\-Length: 12\ex0d\ex0a\ex0d\ex0aHello World!"); .Ve .PP Parse content chunk. .SS "parse_body" .IX Subsection "parse_body" .Vb 1 \& $content = $content\->parse_body(\*(AqHi!\*(Aq); .Ve .PP Parse body chunk and skip headers. .SS "progress" .IX Subsection "progress" .Vb 1 \& my $size = $content\->progress; .Ve .PP Size of content already received from message in bytes. .SS "write" .IX Subsection "write" .Vb 4 \& $content = $content\->write; \& $content = $content\->write(\*(Aq\*(Aq); \& $content = $content\->write($bytes); \& $content = $content\->write($bytes => sub {...}); .Ve .PP Write dynamic content non-blocking, the optional drain callback will be executed once all data has been written. Calling this method without a chunk of data will finalize the \*(L"headers\*(R" and allow for dynamic content to be written later. You can write an empty chunk of data at any time to end the stream. .PP .Vb 8 \& # Make sure previous chunk of data has been written before continuing \& $content\->write(\*(AqHe\*(Aq => sub { \& my $content = shift; \& $content\->write(\*(Aqllo!\*(Aq => sub { \& my $content = shift; \& $content\->write(\*(Aq\*(Aq); \& }); \& }); .Ve .SS "write_chunk" .IX Subsection "write_chunk" .Vb 4 \& $content = $content\->write_chunk; \& $content = $content\->write_chunk(\*(Aq\*(Aq); \& $content = $content\->write_chunk($bytes); \& $content = $content\->write_chunk($bytes => sub {...}); .Ve .PP Write dynamic content non-blocking with chunked transfer encoding, the optional drain callback will be executed once all data has been written. Calling this method without a chunk of data will finalize the \*(L"headers\*(R" and allow for dynamic content to be written later. You can write an empty chunk of data at any time to end the stream. .PP .Vb 8 \& # Make sure previous chunk of data has been written before continuing \& $content\->write_chunk(\*(AqHe\*(Aq => sub { \& my $content = shift; \& $content\->write_chunk(\*(Aqllo!\*(Aq => sub { \& my $content = shift; \& $content\->write_chunk(\*(Aq\*(Aq); \& }); \& }); .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" Mojolicious, Mojolicious::Guides, .