Page
Library
Module
Module type
Parameter
Class
Class type
Source
Http_multipart_formdataSourceRepresents 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 ~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_2pp_parts fmt parts pretty prints a list of Part.t
pp fmt part pretty prints a part.
equal_parts parts1 parts2 returns true if parts1 and parts2 are equal, false otherwise.