1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
module Multipart_form = Piaf_multipart_form.Multipart_form
let pp_extension formatter t =
let payload = match t with `Ietf_token x | `X_token x -> x in
Format.fprintf formatter "%s" payload
let pp_ty = Multipart_form.Content_type.Type.pp
let pp_subty formatter t =
let payload =
match t with `Ietf_token x | `Iana_token x | `X_token x -> x
in
Format.fprintf formatter "%s" payload
let pp_content_type formatter { Multipart_form.Content_type.ty; subty; _ } =
Format.fprintf formatter "%a/%a" pp_ty ty pp_subty subty
let pp_value formatter t =
let ty, payload =
match t with
| Multipart_form.Content_type.Parameters.String x -> "String", x
| Token x -> "Token", x
in
Format.fprintf formatter "%s: %s" ty payload
let pp_disposition_type formatter t =
let ty =
match t with
| `Inline -> "inline"
| `Attachment -> "attachment"
| (`Ietf_token _ | `X_token _) as ext ->
Format.asprintf "%a" pp_extension ext
in
Format.fprintf formatter "%s" ty
let pp_unstructured formatter t =
let pp_one formatter (t : Unstrctrd.elt) =
let s =
match t with
| `Uchar u -> Format.asprintf "Uchar: %c" (Uchar.to_char u)
| `CR -> "CR"
| `LF -> "LF"
| `WSP s -> Format.asprintf "WSP: %s" (s :> string)
| `FWS wsp -> Format.asprintf "FWS: %s" (wsp :> string)
| `d0 -> "d0"
| `OBS_NO_WS_CTL obs -> Format.asprintf "OB_NO_WS_CTL: %c" (obs :> char)
| `Invalid_char invalid_char ->
Format.asprintf "Invalid_char: %c" (invalid_char :> char)
in
Format.fprintf formatter "%s" s
in
Format.pp_print_list
~pp_sep:(fun fmt () -> Format.fprintf fmt "; ")
pp_one
formatter
t
let pp_field formatter t =
let open Multipart_form.Field in
match t with
| Field (_, Content_type, { ty; subty; parameters }) ->
Format.fprintf
formatter
"Content-Type { ty: %a; subty: %a; params: [ %a ] }"
pp_ty
ty
pp_subty
subty
(Format.pp_print_list
~pp_sep:(fun fmt () -> Format.fprintf fmt "; ")
(fun fmt (name, value) ->
Format.fprintf fmt "%s, %a" name pp_value value))
parameters
| Field (_, Content_encoding, enc) ->
Format.fprintf
formatter
"Encoding: %a"
Multipart_form.Content_encoding.pp
enc
| Field (_, Content_disposition, dispo) ->
Format.fprintf
formatter
"Content-Disposition: %a"
Multipart_form.Content_disposition.pp
dispo
| Field (field_name, Field, unstructured) ->
Format.fprintf
formatter
"Field (%a, %a)"
Multipart_form.Field_name.pp
field_name
pp_unstructured
(unstructured :> Unstrctrd.elt list)