The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Mojo::Content - HTTP Content Base Class

SYNOPSIS

    use base 'Mojo::Content';

DESCRIPTION

Mojo::Content is a HTTP content base class.

ATTRIBUTES

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

body_cb

    my $cb = $content->body_cb;

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

buffer

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

filter

    my $filter = $content->filter;
    $content   = $content->filter(Mojo::Filter::Chunked->new);

filter_buffer

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

headers

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

progress_cb

    my $cb   = $content->progress_cb;
    $content = $content->progress_cb(sub {
        my $self = shift;
        print '+';
    });

relaxed

    my $relaxed = $content->relaxed;
    $content    = $content->relaxed(1);

raw_header_size

    my $size = $content->raw_header_size;

METHODS

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

body_contains

    my $found = $content->body_contains('foo bar baz');

body_size

    my $size = $content->body_size;

build_body

    my $string = $content->build_body;

build_headers

    my $string = $content->build_headers;

generate_body_chunk

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

get_body_chunk

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

get_header_chunk

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

has_leftovers

    my $leftovers = $content->has_leftovers;

header_size

    my $size = $content->header_size;

is_chunked

    my $chunked = $content->is_chunked;

is_multipart

    my $multipart = $content->is_multipart;

leftovers

    my $bytes = $content->leftovers;

parse

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

parse_until_body

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

raw_body_size

    my $size = $content->raw_body_size;