1+ open Misc
2+
13type 'content form_data = {
24 fo_name : string ;
35 fo_content : 'content ;
46 fo_filename : string option ;
5- fo_headers : string list Req. StringMap.t ;
7+ fo_headers : string list StringMap .t ;
68}
79
810let make ?(headers =[] ) ?filename ~name content = {
911 fo_name= name; fo_content= content; fo_filename= filename;
10- fo_headers= List. fold_left (fun acc (k , v ) -> Req. StringMap. add k v acc) Req. StringMap. empty headers;
12+ fo_headers= List. fold_left (fun acc (k , v ) -> StringMap. add k v acc) StringMap. empty headers;
1113}
1214
1315let split sep s =
@@ -24,25 +26,25 @@ let split sep s =
2426let process_header ?(debug =false ) map s = match String. split_on_char ':' s with
2527 | [ k; v ] ->
2628 let k, v = String. lowercase_ascii (String. trim k), String. trim v in
27- Req. StringMap. add k (String. split_on_char ',' v) map
29+ StringMap. add k (String. split_on_char ',' v) map
2830 | _ ->
2931 if debug then Format. eprintf " malformed header: %s@." s;
3032 map
3133
3234let make_form_data ?debug ?(index =0 ) ~headers contents =
33- let headers = List. fold_left (process_header ?debug) Req. StringMap. empty headers in
35+ let headers = List. fold_left (process_header ?debug) StringMap. empty headers in
3436 let unquote s =
3537 let n = String. length s in
3638 if n > 1 && String. get s 0 = '"' && String. get s (n-1 ) = '"' then String. sub s 1 (n-2 )
3739 else s in
3840 let fo_content = String. concat " \r\n " contents in
3941 let default = Format. sprintf " part%d" index in
40- let fo_name, fo_filename, fo_headers = match Req. StringMap. find_opt " content-disposition" headers with
42+ let fo_name, fo_filename, fo_headers = match StringMap. find_opt " content-disposition" headers with
4143 | Some [ cd ] ->
4244 let _, params = Req. header_params ?debug cd in
4345 Option. value ~default (List. find_map (fun (k , v ) -> if k= " name" then Some (unquote v) else None ) params),
4446 List. find_map (fun (k , v ) -> if k= " filename" then Some (unquote v) else None ) params,
45- Req. StringMap. remove " content-disposition" headers
47+ StringMap. remove " content-disposition" headers
4648 | _ -> default, None , headers in
4749 { fo_name; fo_filename; fo_headers; fo_content }
4850
@@ -55,7 +57,7 @@ let get_boundary_from_content_type ?debug ct =
5557 | Some b -> Ok b
5658
5759let get_boundary ?debug headers =
58- match Req. StringMap. find_opt " content-type" headers with
60+ match StringMap. find_opt " content-type" headers with
5961 | Some [ ct ] -> get_boundary_from_content_type ?debug ct
6062 | _ -> Error " content-type header not found"
6163
@@ -98,7 +100,7 @@ let produce_form_data ~boundary b data =
98100 Buffer. add_string b (" content-disposition: form-data; name=\" " ^ data.fo_name ^ " \" " );
99101 Option. iter (fun filename -> Buffer. add_string b (" ; filename=\" " ^ filename ^ " \" " )) data.fo_filename;
100102 Buffer. add_string b " \r\n " ;
101- Req. StringMap. iter (fun k lv ->
103+ StringMap. iter (fun k lv ->
102104 Buffer. add_string b (k ^ " :" );
103105 let () = match lv with
104106 | [] -> ()
0 commit comments