DeterministicESPAsyncWebServer v6.27.1
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
multipart.h File Reference

In-place multipart/form-data parser (RFC 7578). More...

Go to the source code of this file.

Classes

struct  MultipartPart
 One parsed part from a multipart body. More...
 
struct  Multipart
 Container for all parsed parts of a multipart body. More...
 

Functions

bool multipart_parse (HttpReq *req, Multipart *mp)
 Parse the body of req as multipart/form-data.
 
const char * multipart_get_field (const Multipart *mp, const char *field)
 Look up a field value across all parsed parts by name.
 

Detailed Description

In-place multipart/form-data parser (RFC 7578).

Parses the body already stored in HttpReq::body[]. The parser modifies the body buffer in-place by inserting null terminators, so part->data pointers are valid only while the HttpReq lives (before http_reset()).

The scan is length-bounded over HttpReq::body_len and matches the full \r\n--boundary delimiter (RFC 2046), so a binary part is safe: embedded NUL bytes and even the raw boundary string inside the payload do not truncate it (only the true CRLF--boundary delimiter ends a part). Read a binary part via part->data + part->data_len (the in-place NUL terminator is a convenience for text parts, not a length).

Limitations

  • Maximum parts: MAX_MULTIPART_PARTS (default 4).
  • Maximum total body size: BODY_BUF_SIZE bytes.
  • Only name and filename are extracted from Content-Disposition; other parameters are ignored.
  • Boundary value must be ≤ MAX_BOUNDARY_LEN bytes (RFC 2046 cap: 70).
Author
Douglas Quigg (dstroy0)
Date
2026

Definition in file multipart.h.

Function Documentation

◆ multipart_parse()

bool multipart_parse ( HttpReq req,
Multipart mp 
)

Parse the body of req as multipart/form-data.

Reads the boundary from the Content-Type header, then scans req->body in-place, null-terminating each part's headers and data.

Parameters
reqFully-parsed HTTP request (must be in ParseState::PARSE_COMPLETE state).
mpOutput structure; filled on success.
Returns
true if at least one part was found, false on parse error.

Definition at line 44 of file multipart.cpp.

References HttpReq::body, HttpReq::body_len, MultipartPart::data, MultipartPart::data_len, MultipartPart::filename, http_get_header(), MAX_BOUNDARY_LEN, MAX_MULTIPART_PARTS, MultipartPart::name, Multipart::part_count, Multipart::parts, and MultipartPart::type.

◆ multipart_get_field()

const char * multipart_get_field ( const Multipart mp,
const char *  field 
)

Look up a field value across all parsed parts by name.

Returns the data pointer of the first part whose name matches field. Useful for simple form submissions where each field has a unique name.

Parameters
mpParsed multipart result.
fieldForm field name to search for.
Returns
Part data (null-terminated), or nullptr if not found.

Definition at line 164 of file multipart.cpp.

References MultipartPart::data, MultipartPart::name, Multipart::part_count, and Multipart::parts.