package http-multipart-formdata
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=73e43c4e31560499f6998ebddd117f76b5e9cfe5edafa390f4a088e1f4fa7fa2
sha512=fc24b6238406aba0a452262ee7879e58f2fc307341dad43baae61a39e5eae0f4ce54913a06d0d26af871267827f95e7ed4281d38f6b50177fdf91b6ee6828118
doc/http-multipart-formdata/Http_multipart_formdata/index.html
Module Http_multipart_formdata
Source
Types
Represents a parsed multipart part. A part corresponds to a submitted form field data in a HTTP request.
Represents a parsed HTTP multipart/form-data
request as a key/value
map. Submitted form field name is the key value.
A key may be associated in zero or more values.
Represents error while parsing http multipart formdata.
Parse
parse ~content_type_header ~body
returns a parsed HTTP multiparts such that it can be queried using ocaml Stdlib.Map
functions.
content_type_header
is the HTTP request Content-Type
header. Note the value contains both the header name and value. It is used to parse a boundary
value.
body
is the raw HTTP POST request body content.
Examples
module M = Http_multipart_formdata
;;
let content_type_header =
"Content-Type: multipart/form-data; \
boundary=---------------------------735323031399963166993862150"
in
let body =
[ {||}
; {|-----------------------------735323031399963166993862150|}
; {|Content-Disposition: form-data; name="text1"|}
; {||}
; {|text default|}
; {|-----------------------------735323031399963166993862150|}
; {|Content-Disposition: form-data; name="text2"|}
; {||}
; {|aωb|}
; {|-----------------------------735323031399963166993862150|}
; {|Content-Disposition: form-data; name="file1"; filename="a.txt"|}
; {|Content-Type: text/plain|}
; {||}
; {|Content of a.txt.|}
; {||}
; {|-----------------------------735323031399963166993862150|}
; {|Content-Disposition: form-data; name="file2"; filename="a.html"|}
; {|Content-Type: text/html|}
; {||}
; {|<!DOCTYPE html><title>Content of a.html.</title>|}
; {||}
; {|-----------------------------735323031399963166993862150|}
; {|Content-Disposition: form-data; name="file3"; filename="binary"|}
; {|Content-Type: application/octet-stream|}
; {||}
; {|aωb|}
; {|-----------------------------735323031399963166993862150--|}
]
|> String.concat "\r\n"
in
let mp = M.parse ~content_type_header ~body in
let file1_1 = M.Map.find "file1" mp in
let file1_2 =
[ { M.Part.body = Bytes.of_string "\r\nContent of a.txt.\r\n\r\n"
; name = "file1"
; content_type = "text/plain"
; filename = Some "a.txt"
; parameters = M.Map.empty
}
]
in
M.equal_parts file1_1 file1_2
Pretty Printers
pp_parts fmt parts
pretty prints a list of Part.t
pp fmt part
pretty prints a part
.
Equals
equal_parts parts1 parts2
returns true
if parts1
and parts2
are equal, false
otherwise.