mirror of
https://github.com/c-cube/tiny_httpd.git
synced 2025-12-05 19:00:32 -05:00
feat multipart-form: expose content_disposition
This commit is contained in:
parent
66f87b7bda
commit
b966a9eccc
3 changed files with 16 additions and 7 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
open Tiny_httpd
|
||||
module Slice = Iostream.Slice
|
||||
module Content_disposition = Content_disposition
|
||||
|
||||
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
|
||||
| Some ("boundary", "") -> ()
|
||||
| Some ("boundary", s) ->
|
||||
let s =
|
||||
if s.[0] = '"' && s.[String.length s - 1] = '"' then
|
||||
String.sub s 1 (String.length s - 2)
|
||||
else
|
||||
s
|
||||
in
|
||||
let s = Utils_.remove_quotes s in
|
||||
boundary := Some (`boundary s)
|
||||
| _ -> ())
|
||||
tl;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
(** Parser for multipart/form-data *)
|
||||
(** Streaming parser for multipart/form-data *)
|
||||
|
||||
module Content_disposition = Content_disposition
|
||||
|
||||
type st
|
||||
(** Parser state *)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
let spf = Printf.sprintf
|
||||
|
||||
let string_eq ~a ~a_start ~b ~len : bool =
|
||||
assert (len <= String.length b);
|
||||
if String.length a >= a_start + len then (
|
||||
|
|
@ -16,3 +18,11 @@ let split1_on ~c s =
|
|||
match String.index s c with
|
||||
| exception Not_found -> None
|
||||
| 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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue