NAME

HTTP::Body::MultiPart - HTTP Body Multipart Parser

SYNOPSIS

use HTTP::Body::MultiPart;

DESCRIPTION

HTTP Body Multipart Parser for multipart/form-data bodies.

A part with a non-empty filename in its Content-Disposition is an upload: its data is written to a temporary file as it arrives, and the part is stored with "upload" in HTTP::Body once it is complete. Every other part is stored with "param" in HTTP::Body and "part_data" in HTTP::Body, except a part with an empty filename (a file field left empty), which is dropped.

See "Limits" in HTTP::Body for the limits on parts and their headers, and "CONFIGURING UPLOAD TEMPORARY FILES" in HTTP::Body for the temporary files.

METHODS

init

Takes the boundary from the content type, croaking if it has none, and starts the parser in the preamble state.

spin

Runs the parse method of the current state (parse_preamble, parse_boundary, parse_header or parse_body) until one of them needs more data or the body is done.

boundary

The boundary parameter of the content type.

boundary_begin

-- followed by the boundary.

boundary_end

boundary_begin followed by --.

crlf

The line ending of a multipart body, "\x0D\x0A".

delimiter_begin

crlf followed by boundary_begin: the delimiter that ends the data of a part.

delimiter_end

crlf followed by boundary_end: the close delimiter that ends the body.

parse_preamble

Drops the preamble before the first boundary and moves on to the boundary state. Until the boundary is found, only as many bytes are kept as could be its start.

parse_boundary

Reads a delimiter line. A delimiter starts the next part and the header state; a close delimiter ends the body, and whatever follows it (padding, an epilogue) is ignored. Croaks on a line that is neither, and when the body has more than $HTTP::Body::MultiPart::max_parts parts.

parse_header

Reads a part's header block, up to the blank line, into $part->{headers}, keyed by field name with the first letter of each word upper-cased; a field that occurs more than once gets an array reference. A continuation line is joined to the line before it, and a line that is no header field is dropped. Croaks when the block exceeds $HTTP::Body::MultiPart::max_header_size bytes or $HTTP::Body::MultiPart::max_header_lines lines.

parse_body

Passes a part's data on to handler as it arrives, holding back only as many bytes as could be the start of the next delimiter. At the delimiter it sets $part->{done}, calls handler a last time and moves on to the boundary state.

handler

Called by parse_body with the part each time data arrives. On the first call it takes the part's name and filename from its Content-Disposition, unless a subclass has named the part already, and strips any NUL from the filename. A part with a non-empty filename gets a temporary file, and its data is written there as it arrives. Once the part is done it is stored as described under "DESCRIPTION". Croaks when the temporary file can not be written.

SUPPORT

See HTTP::Body

AUTHOR

Christian Hansen, ch@ngmedia.com

LICENSE

This library is free software . You can redistribute it and/or modify it under the same terms as perl itself.