Use SwiftNIO HTTPHeaders parser to parse multipart header fields?

i am trying to implement multipart/form-data HTTP requests, and now need to parse the per-part HTTP headers:

Content-Disposition: form-data; name="file1"; filename="test.txt"
Content-Type: application/octet-stream

is there a way to re-use SwiftNIO’s HTTP header parser for this?

I don't think so, NIO uses http_parser.c, which is specifically an HTTP parser (e.g. expects a request or response line). Maybe you can get away w/ prepending one?
But I think the MIME parsing rules are different in details to just HTTP headers.

i see. i did not expect to be spending this much time on something this simple; it seems we don’t have any existing multipart parsers that don’t depend on Foundation :(

I have this, not sure how good it is :-) MacroExpress/MultiPartParser.swift at develop · Macro-swift/MacroExpress · GitHub

1 Like