DeterministicESPAsyncWebServer 1.2.0
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...

#include "DetWebServerConfig.h"
#include "presentation.h"

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()).

Limitations

  • Maximum parts: MAX_MULTIPART_PARTS (default 4).
  • Maximum total body size: BODY_BUF_SIZE bytes.
  • Binary payloads containing the boundary string will be truncated.
  • 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 PARSE_COMPLETE state).
mpOutput structure; filled on success.
Returns
true if at least one part was found, false on parse error.

Definition at line 39 of file multipart.cpp.

References HttpReq::body, 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 152 of file multipart.cpp.

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