http_multipart
This library provides a higher-level multipart helper layer on top of
the http_core library. It does not replace the low-level multipart
wire support already implemented in http_core; instead it wraps the
normalized multipart body and part terms, adds form-data field and file
helpers, and delegates raw parsing and generation to the existing
http_core predicates.
API documentation
Open the ../../apis/library_index.html#http_multipart link in a web browser.
Loading
To load the library, load the loader.lgt file:
| ?- logtalk_load(http_multipart(loader)).
Testing
To test this library, load the tester.lgt file:
| ?- logtalk_load(http_multipart(tester)).
Current scope
The current version provides:
body/3for constructing validated normalized multipart body terms.part/4for constructing validated normalized multipart part terms.is_body/1andis_part/1for testing normalized multipart body and part terms.media_type/2andparts/2for inspecting multipart body terms.part_headers/2,part_body/2, andpart_properties/2for inspecting multipart part terms.field/4andfields/2for inspecting textual form-data field parts and multipart/form-data bodies.file/6andfiles/2for inspecting form-data file parts and multipart/form-data bodies.field_part/4andfile_part/6for constructing outgoing form-data field and file parts.form_data_body/2for constructing amultipart/form-databody from an ordered list of parameter-aware field and file descriptors.parse/4andgenerate/3as multipart-specific wrappers around the existinghttp_core::parse_body/4andhttp_core::generate_body/3predicates.
Form-data descriptors
The parameter-aware helper predicates use the following descriptor shapes:
field(Name, Value, Parameters)file(Name, Filename, MediaType, Payload, Parameters)
In both cases, Parameters is an ordered list of extra
Content-Disposition: form-data parameters represented as
Name-Value pairs. The reserved name and filename parameters
remain explicit helper arguments and must not be repeated in the
Parameters list.
Additional Content-Disposition: form-data parameters are preserved
as ordered Name-Value pairs. Any special semantics for extended
parameters such as filename* are intentionally left to callers.
Normalized terms
Multipart bodies use the normalized http_core body term:
content(MediaType, multipart(Parts))
Multipart parts use the recursive normalized term:
part(Headers, Body, Properties)
Current workflow
Use
form_data_body/2when you want to assemble a normalizedmultipart/form-databody explicitly.Use the
field/4,fields/2,file/6, andfiles/2predicates when you want to inspect multipart form-data bodies after parsing.The
http_clientlibrary can send common form-data requests directly from aform_data(Items)descriptor.The
http_serverlibrary keeps multipart request bodies in the normalized form expected by this library, so handlers can inspect incoming multipart requests without reparsing them.
Current limitations
The library is entirely in-memory.
Textual field helpers target simple text field payloads. If a part has a non-text body or a more specialized encoding, callers should use the generic part accessors instead.
Multipart wire parsing and generation require a boundary parameter in the effective
Content-Typemetadata or an explicitboundary/1option, exactly as in the underlyinghttp_corelibrary.The library does not provide streaming sinks, temp-file policies, or large-upload orchestration.