package multipart_form

  1. Overview
  2. Docs
Multipart-form: RFC2183, RFC2388 & RFC7578

Install

Dune Dependency

Authors

Maintainers

Sources

multipart_form-v0.1.0.tbz
sha256=65d9dde4fbb65da203888d299aaedbd0778f44169d85a4c7c6d271a21747362e
sha512=6ecde468b5649a705bb9ed57d3c6dde5520ad6d87c710c77d2417d077f28006b2e7399f1d32b82bc885f8e1f6d1a7cc8a614e45e9385f72095b393f599eb9f2b

Description

Implementation of RFC7578 in OCaml

Returning values from forms: multipart/form-data

Published: 15 Sep 2020

README

Multipart-form

This library provides a /stream-way/ to extracts values from a multipart/form-data HTTP 1.{0,1} document. The library does not requires an HTTP server but can be used with one of them. The library is pretty straightforward to co-exist with:

The multipart/form-data appears when you want to propose a form to the client. You can encode values given by the client into the URL with application/x-www-form-urlencoded or, if you want to let the client to upload a file, multipart/form-data is required.

This library wants to process the second case.

A /stream/ API

Due to the use of angstrom, multipart_form is able to manipulate a /stream/ instead of process entirely the given document. Indeed, when the client wants to upload a file, it will be a shame to store twice times the file into the memory heap (firstly, keep entirely the multipart/form-data document, secondly, extract the file from the first one).

So, the user is able to concurrently /eat/ the multipart/form-data document, feed the angstrom's state and save a part (such as the uploaded file) to another location. By this way, we keep a control about memory consumption.

Simple usage

multipart_form has its own definition of the Content-Type needed to start the analyse of the given document. From cohttp or httpaf, you are able to extract it as is and give it to Multipart_form.Content_type.of_string to get a well-defined Content-Type value.

Then, you can start to /parse/ the document with this value and an emitters.

An emitters is a simple function which must give to the process a way to /store/ the part and a unique identifier to be able to retrieve contents at the end of the process:

type 'id emitters = unit -> 'id * (string option -> unit)

A use of Lwt_stream.create can gives you such required value.

Status of the library

This library was done for my personal use and I probably missed some useful elements for a basic user who wants to process a multipart/form-data document. So, feel free to make an issue if you think that something is missed.

Dependencies (14)

  1. bigstringaf < "0.9.0"
  2. bigarray-compat
  3. ke >= "0.4"
  4. fmt
  5. result
  6. pecu >= "0.4"
  7. stdlib-shims
  8. uutf
  9. rresult
  10. unstrctrd >= "0.2"
  11. base64 >= "3.0.0"
  12. angstrom >= "0.14.0"
  13. dune >= "2.0.0"
  14. ocaml >= "4.08.0"

Dev Dependencies (2)

  1. alcotest with-test
  2. ocaml with-test & < "5.2"

Used by

None

Conflicts

None