mirror of
https://github.com/c-cube/tiny_httpd.git
synced 2025-12-06 03:05:29 -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
|
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;
|
||||||
|
|
|
||||||
|
|
@ -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 *)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue