Skip to content

Commit 0b34c96

Browse files
committed
fix multipart: no \r\n before boundary after all
1 parent 8f0dac2 commit 0b34c96

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/multipart_form/tiny_httpd_multipart_form_data.ml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ let create ?(buf_size = 64 * 1024) ?(out_buf_size = 8 * 1024) ~boundary ic : st
4646

4747
type chunk = Delim | Eof | Read of int
4848

49-
let[@inline] min_len_ (self : st) : int = 4 + String.length self.boundary
49+
let[@inline] min_len_ (self : st) : int = 2 + String.length self.boundary
5050

5151
exception Found_boundary of int
5252

@@ -74,16 +74,14 @@ let rec read_chunk_ (self : st) buf i_buf len : chunk =
7474
) else (
7575
try
7676
let i = ref 0 in
77-
let end_pos = min len self.buf.len - 4 - String.length self.boundary in
77+
let end_pos = min len self.buf.len - 2 - String.length self.boundary in
7878
while !i <= end_pos do
7979
if
80-
Bytes.unsafe_get self.buf.bs !i = '\r'
81-
&& Bytes.unsafe_get self.buf.bs (!i + 1) = '\n'
82-
&& Bytes.unsafe_get self.buf.bs (!i + 2) = '-'
83-
&& Bytes.unsafe_get self.buf.bs (!i + 3) = '-'
80+
Bytes.unsafe_get self.buf.bs !i = '-'
81+
&& Bytes.unsafe_get self.buf.bs (!i + 1) = '-'
8482
&& Utils_.string_eq
8583
~a:(Bytes.unsafe_to_string self.buf.bs)
86-
~a_start:(!i + 4) ~b:self.boundary
84+
~a_start:(!i + 2) ~b:self.boundary
8785
~len:(String.length self.boundary)
8886
then
8987
raise_notrace (Found_boundary !i);
@@ -95,7 +93,7 @@ let rec read_chunk_ (self : st) buf i_buf len : chunk =
9593
Read n_read
9694
with
9795
| Found_boundary 0 ->
98-
shift_left_ self.buf (4 + String.length self.boundary);
96+
shift_left_ self.buf (2 + String.length self.boundary);
9997
Delim
10098
| Found_boundary n ->
10199
let n_read = min n len in
@@ -191,7 +189,6 @@ and parse_headers_rec (self : st) acc : Headers.t =
191189
)
192190
| i ->
193191
let line = Bytes.sub_string self.buf_out.bs 0 i in
194-
Printf.eprintf "parse header line %S\n%!" line;
195192
shift_left_ self.buf_out (i + 2);
196193
if line = "" then
197194
List.rev acc

0 commit comments

Comments
 (0)