Is there a lightweight multipart/form-data parser in C or C++?

14,406

Solution 1

I know this question is a couple of years old now, but I needed the same and ended up using this:

https://github.com/iafonov/multipart-parser-c

Solution 2

Yes, there one. No secret it is my own. Feel free to use it. The link is: MPFDParser. It has no dependencies at all.

Solution 3

cgicc supports it... But is written quite badly and relays on entry buffer in memory.

Solution 4

mimetic claims to support it. I think GNU cgicc may also support it.

Share:
14,406
Hongli
Author by

Hongli

CTO, entrepreneur & consultant. Author of the Passenger application server, which is middleware that is in use by over 650.000 websites world-wide, including Apple, to help them ship software faster and to handle millions of customers per day. I have a wide range of technological competences & interests. Current specializations: full-stack web dev; Ruby development; DevOps, infrastructure & containerization; debugging, scaling & optimizing apps at scale; and systems programming. Available for hire or contracting work.

Updated on June 07, 2022

Comments

  • Hongli
    Hongli almost 2 years

    I'm looking at integrating multipart form-data parsing in a web server module so that I can relieve backend web applications (often written in dynamic languages) from parsing the multipart data themselves. The multipart grammar (RFC 2046) looks non-trivial and if I implement it by hand a lot of things can go wrong. Is there already a good, lightweight multipart/form-data parser written in C or C++? I'm looking for one with no external dependencies other than the C or C++ standard library. I don't need email attachment handling or buffered I/O classes or a portability runtime or whatever, just multipart/form-data parsing.

    Things that I've considered:

    • GMime - depends on glib, so no go.
    • libapreq - too large, depends on APR, badly documented, no unit tests.

    I've also looked at writing a parser with Ragel, but I can't figure out how to do it because the grammar is not static: the boundary can change arbitrarily.

  • Michael Böckling
    Michael Böckling about 7 years
    Definitely check the issues though! E.g. the boundary term must be prefixed with "--" already, or else it won't work.