++ed by:
JHTHORSEN RBO GVL EXC WRUPPERT

112 PAUSE user(s)
138 non-PAUSE user(s).

Sebastian Riedel

NAME

Mojo::Message - HTTP 1.1 Message Base Class

SYNOPSIS

  use Mojo::Base 'Mojo::Message';

DESCRIPTION

Mojo::Message is an abstract base class for HTTP 1.1 messages as described in RFC 2616 and RFC 2388.

ATTRIBUTES

Mojo::Message implements the following attributes.

content

  my $message = $message->content;
  $message    = $message->content(Mojo::Content::Single->new);

Content container, defaults to a Mojo::Content::Single object.

default_charset

  my $charset = $message->default_charset;
  $message    = $message->default_charset('UTF-8');

Default charset used for form data parsing.

dom_class

  my $class = $message->dom_class;
  $message  = $message->dom_class('Mojo::DOM');

Class to be used for DOM manipulation, defaults to Mojo::DOM.

json_class

  my $class = $message->json_class;
  $message  = $message->json_class('Mojo::JSON');

Class to be used for JSON deserialization with json, defaults to Mojo::JSON.

max_line_size

  my $size = $message->max_line_size;
  $message = $message->max_line_size(1024);

Maximum line size in bytes, defaults to 10240.

max_message_size

  my $size = $message->max_message_size;
  $message = $message->max_message_size(1024);

Maximum message size in bytes, defaults to 5242880.

on_finish

  my $cb   = $message->on_finish;
  $message = $message->on_finish(sub {
    my $self = shift;
  });

Callback called after message building or parsing is finished.

on_progress

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

Progress callback.

METHODS

Mojo::Message inherits all methods from Mojo::Base and implements the following new ones.

at_least_version

  my $success = $message->at_least_version('1.1');

Check if message is at least a specific version.

body

  my $string = $message->body;
  $message   = $message->body('Hello!');
  $message   = $message->body(sub {...});

Helper for simplified content access.

body_params

  my $params = $message->body_params;

POST parameters.

body_size

  my $size = $message->body_size;

Size of the body in bytes.

build_body

  my $string = $message->build_body;

Render whole body.

build_headers

  my $string = $message->build_headers;

Render all headers.

build_start_line

  my $string = $message->build_start_line;

Render start line.

  my $cookie  = $message->cookie('foo');
  my @cookies = $message->cookie('foo');

Access message cookies.

dom

  my $dom        = $message->dom;
  my $collection = $message->dom('a[href]');

Turns content into a Mojo::DOM object and takes an optional selector to perform a find on it right away, which returns a collection.

error

  my $message          = $message->error;
  my ($message, $code) = $message->error;
  $message             = $message->error('Parser error.');
  $message             = $message->error('Parser error.', 500);

Parser errors and codes.

fix_headers

  $message = $message->fix_headers;

Make sure message has all required headers for the current HTTP version.

get_body_chunk

  my $string = $message->get_body_chunk($offset);

Get a chunk of body data starting from a specific position.

get_header_chunk

  my $string = $message->get_header_chunk($offset);

Get a chunk of header data, starting from a specific position.

get_start_line_chunk

  my $string = $message->get_start_line_chunk($offset);

Get a chunk of start line data starting from a specific position.

has_leftovers

  my $leftovers = $message->has_leftovers;

CHeck if message parser has leftover data.

header_size

  my $size = $message->header_size;

Size of headers in bytes.

headers

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

Header container, defaults to a Mojo::Headers object.

is_chunked

  my $chunked = $message->is_chunked;

Check if message content is chunked.

is_done

  my $done = $message->is_done;

Check if parser is done.

is_limit_exceeded

  my $limit = $message->is_limit_exceeded;

Check if message has exceeded max_line_size or max_message_size.

is_multipart

  my $multipart = $message->is_multipart;

Check if message content is multipart.

json

  my $object = $message->json;
  my $array  = $message->json;

Decode JSON message body directly using Mojo::JSON if possible, returns undef otherwise.

leftovers

  my $bytes = $message->leftovers;

Remove leftover data.

param

  my $param  = $message->param('foo');
  my @params = $message->param('foo');

Access GET and POST parameters.

parse

  $message = $message->parse('HTTP/1.1 200 OK...');

Parse message chunk.

parse_until_body

  $message = $message->parse_until_body('HTTP/1.1 200 OK...');

Parse message chunk until the body is reached.

start_line_size

  my $size = $message->start_line_size;

Size of the start line in bytes.

to_string

  my $string = $message->to_string;

Render whole message.

upload

  my $upload  = $message->upload('foo');
  my @uploads = $message->upload('foo');

Access file uploads.

uploads

  my $uploads = $message->uploads;

All file uploads.

version

  my $version = $message->version;
  $message    = $message->version('1.1');

HTTP version of message.

write

  $message->write('Hello!');
  $message->write('Hello!', sub {...});

Write dynamic content, the optional drain callback will be invoked once all data has been written.

write_chunk

  $message->write_chunk('Hello!');
  $message->write_chunk('Hello!', sub {...});

Write chunked content, the optional drain callback will be invoked once all data has been written.

SEE ALSO

Mojolicious, Mojolicious::Guides, http://mojolicio.us.