feat multipart-form: expose content_disposition

This commit is contained in:
Simon Cruanes 2024-12-02 14:56:35 -05:00
parent 66f87b7bda
commit b966a9eccc
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
3 changed files with 16 additions and 7 deletions

View file

@ -2,6 +2,7 @@
open Tiny_httpd open Tiny_httpd
module Slice = Iostream.Slice module Slice = Iostream.Slice
module Content_disposition = Content_disposition
let spf = Printf.sprintf let spf = Printf.sprintf
@ -216,12 +217,7 @@ let parse_content_type (hs : Tiny_httpd.Headers.t) : _ option =
match Utils_.split1_on ~c:'=' @@ String.trim s with match Utils_.split1_on ~c:'=' @@ String.trim s with
| Some ("boundary", "") -> () | Some ("boundary", "") -> ()
| Some ("boundary", s) -> | Some ("boundary", s) ->
let s = let s = Utils_.remove_quotes s in
if s.[0] = '"' && s.[String.length s - 1] = '"' then
String.sub s 1 (String.length s - 2)
else
s
in
boundary := Some (`boundary s) boundary := Some (`boundary s)
| _ -> ()) | _ -> ())
tl; tl;

View file

@ -1,4 +1,7 @@
(** Parser for multipart/form-data *) (** Streaming parser for multipart/form-data *)
module Content_disposition = Content_disposition
type st type st
(** Parser state *) (** Parser state *)

View file

@ -1,3 +1,5 @@
let spf = Printf.sprintf
let string_eq ~a ~a_start ~b ~len : bool = let string_eq ~a ~a_start ~b ~len : bool =
assert (len <= String.length b); assert (len <= String.length b);
if String.length a >= a_start + len then ( if String.length a >= a_start + len then (
@ -16,3 +18,11 @@ let split1_on ~c s =
match String.index s c with match String.index s c with
| exception Not_found -> None | exception Not_found -> None
| i -> Some (String.sub s 0 i, String.sub s (i + 1) (String.length s - i - 1)) | i -> Some (String.sub s 0 i, String.sub s (i + 1) (String.length s - i - 1))
let remove_quotes s : string =
if String.length s < 2 then
s
else if s.[0] = '"' && s.[String.length s - 1] = '"' then
String.sub s 1 (String.length s - 2)
else
s