Name

SPVM::Mojo::Content::Single - HTTP content

Description

Mojo::Content::Single class in SPVM is a container for HTTP content, based on RFC 7230 and RFC 7231.

Usage

use Mojo::Content::Single;

my $single = Mojo::Content::Single->new;
$single->parse("Content-Length: 12\x0d\x0a\x0d\x0aHello World!");
say $single->headers->content_length;

Super Class

Mojo::Content

Fields

asset

has asset : rw Mojo::Asset;

The actual content, defaults to a Mojo::Asset::Memory object with Mojo::Asset::Memory#auto_upgrade enabled.

auto_upgrade

has auto_upgrade : rw byte;

Try to detect multipart content and automatically upgrade to a Mojo::Content::MultiPart object, defaults to a true value.

Class Methods

static method new : Mojo::Content::Single ();

Construct a new Mojo::Content::Single object and subscribe to event Mojo::Content#read with default content parser.

Instance Methods

body_contains

method body_contains : int ($chunk : string);

Check if content contains a specific string.

body_size

method body_size : int ();

Content size in bytes.

clone

method clone : Mojo::Content::Single ();

Return a new Mojo::Content::Single object cloned from this content if possible, otherwise return undef.

get_body_chunk

method get_body_chunk : string ($offset : int);

Get a chunk of content starting from a specific position. Note that it might not be possible to get the same chunk twice if content was generated dynamically.

parse

method parse : Mojo::Content ($chunk : string);

Parse content chunk and upgrade to Mojo::Content::MultiPart object if necessary.

See Also

Copyright & License

Copyright (c) 2025 Yuki Kimoto

MIT License