mirror of
https://github.com/c-cube/tiny_httpd.git
synced 2025-12-05 19:00:32 -05:00
missing file
This commit is contained in:
parent
ce6119d456
commit
8f0dac2dfe
1 changed files with 31 additions and 0 deletions
31
src/multipart_form/content_disposition.ml
Normal file
31
src/multipart_form/content_disposition.ml
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
open Utils_
|
||||
|
||||
type t = { kind: string; name: string option; filename: string option }
|
||||
|
||||
(** Simple display *)
|
||||
let to_string (self : t) =
|
||||
let stropt = function
|
||||
| None -> "None"
|
||||
| Some s -> spf "%S" s
|
||||
in
|
||||
spf "{kind=%S; name=%s; filename=%s}" self.kind (stropt self.name)
|
||||
(stropt self.filename)
|
||||
|
||||
let parse (hs : Tiny_httpd.Headers.t) : t option =
|
||||
match Tiny_httpd.Headers.get "content-disposition" hs with
|
||||
| None -> None
|
||||
| Some s ->
|
||||
(match String.split_on_char ';' s with
|
||||
| [] ->
|
||||
failwith (Printf.sprintf "multipart: invalid content-disposition %S" s)
|
||||
| kind :: tl ->
|
||||
let name = ref None in
|
||||
let filename = ref None in
|
||||
List.iter
|
||||
(fun s ->
|
||||
match Utils_.split1_on ~c:'=' @@ String.trim s with
|
||||
| Some ("name", v) -> name := Some (Utils_.remove_quotes v)
|
||||
| Some ("filename", v) -> filename := Some (Utils_.remove_quotes v)
|
||||
| _ -> ())
|
||||
tl;
|
||||
Some { kind; name = !name; filename = !filename })
|
||||
Loading…
Add table
Reference in a new issue