Hcs.Multipart
hcs · API reference
Multipart form-data parsing.
Use this module for file uploads and form submissions encoded as multipart/form-data. It consumes request body streams and returns parsed fields/files according to configured limits.
Multipart form data parsing.
The parser keeps at most one input chunk plus a boundary-sized suffix while streaming a body. Mutable scanning state is confined to parser; callers only observe immutable part metadata and pull streams.
module Hmf = Http_multipart_formdatatype part = {
name : string;
filename : string option;
content_type : string;
data : string;
}type error =
| Missing_content_type
| Not_multipart
| Missing_boundary
| Invalid_boundary of string
| Parse_error of stringval error_to_string : error -> stringval is_multipart : Request.t -> boolval has_boundary_parameter : string -> boolval boundary : Request.t -> (Hmf.boundary, error) resultval find_part : string -> part list -> part optionval find_file : string -> part list -> part optionval to_assoc : part list -> (string * part) listtype stream_part = {
name : string;
filename : string option;
content_type : string;
body : Cstruct.t Stream.Async.t;
}type phase =
| Preamble
| Header
| Body
| End
| Failedtype parser = {
hmf_boundary : Hmf.boundary;
opening_boundary : string;
body_boundary : string;
body_stream : unit -> Cstruct.t option;
mutable pending : string;
mutable input_ended : bool;
mutable phase : phase;
mutable active_body : bool;
mutable failure : string option;
}val fail : parser -> string -> unitval append_input : parser -> unitval drop_prefix : parser -> int -> unitval substring_at : string -> string -> int -> booltype boundary_match =
| Found of int * bool
| Need_more
| Not_foundval find_boundary : string -> string -> boundary_matchval seek_opening_boundary : parser -> unitval find_substring : string -> string -> int optionval read_header_block : parser -> string optionval parse_header :
parser ->
string ->
(string * string option * string, string) resultval finish_boundary : parser -> bool -> unitval make_body_stream : parser -> Cstruct.t Stream.Async.tval create_parser : Request.t -> (parser, error) resultval next_part : parser -> stream_part optionval parser_result : parser -> 'a -> ('a, error) resultval iter_parts : (stream_part -> 'a) -> parser -> (unit, error) resultval fold_parts :
(stream_part -> 'a -> 'a) ->
'a ->
parser ->
('a, error) resultval collect_body : stream_part -> stringval parse : Request.t -> (part list, error) resultval parse_assoc : Request.t -> ((string * part) list, error) result