NAME

Mojo::Content - Content

SYNOPSIS

use Mojo::Content;

my $content = Mojo::Content->new;
$content->parse("Content-Length: 12\r\n\r\nHello World!");

DESCRIPTION

Mojo::Content is a container for HTTP content.

ATTRIBUTES

Mojo::Content inherits all attributes from Mojo::Stateful and implements the following new ones.

body_length

my $body_length = $content->body_length;

buffer

my $buffer = $content->buffer;
$content   = $content->buffer(Mojo::Buffer->new);

build_body_cb

build_body_callback

my $cb = $content->build_body_cb;
my $cb = $content->build_body_callback;

$counter = 1;
$content = $content->build_body_callback(sub {
    my $self  = shift;
    my $chunk = '';
    $chunk    = "hello world!" if $counter == 1;
    $chunk    = "hello world2!\n\n" if $counter == 2;
    $counter++;
    return $chunk;
});

build_headers_cb

build_header_callback

my $cb = $content->build_headers_cb;
my $cb = $content->build_headers_callback;

$content = $content->build_headers_callback(sub {
    my $h = Mojo::Headers->new;
    $h->content_type('text/plain');
    return $h->to_string;
});

file

my $file = $content->file;
$content = $content->file(Mojo::File::Memory->new);

filter_buffer

my $filter_buffer = $content->filter_buffer;
$content          = $content->filter_buffer(Mojo::Buffer->new);

header_length

my $header_length = $content->header_length;

headers

my $headers = $content->headers;
$content    = $content->headers(Mojo::Headers->new);

parse_body_cb

parse_body_callback

my $cb   = $content->parse_body_cb;
my $cb   = $content->parse_body_callback;
$content = $content->parse_body_callback(sub {
    my $self = shift;
    # Do stuff! :)
});

raw_header_length

my $raw_header_length = $content->raw_header_length;

raw_body_length

my $raw_body_length = $content->raw_body_length;

METHODS

Mojo::Content inherits all methods from Mojo::Stateful and implements the following new ones.

build_body

my $string = $content->build_body;

build_headers

my $string = $content->build_headers;

body_contains

my $found = $content->body_contains;

get_body_chunk

my $chunk = $content->get_body_chunk(0);

get_header_chunk

my $chunk = $content->get_header_chunk(13);

is_chunked

my $chunked = $content->is_chunked;

is_multipart

my $multipart = $content->is_multipart;

parse

$content = $content->parse("Content-Length: 12\r\n\r\nHello World!");