mirror of
https://github.com/c-cube/tiny_httpd.git
synced 2025-12-07 03:35:34 -05:00
fix: missing crlf between chunks
This commit is contained in:
parent
c16e386338
commit
8d33f84022
1 changed files with 13 additions and 5 deletions
|
|
@ -358,7 +358,14 @@ module Request = struct
|
||||||
(* decode a "chunked" stream into a normal stream *)
|
(* decode a "chunked" stream into a normal stream *)
|
||||||
let read_stream_chunked_ ?(buf=Buf_.create()) (bs:byte_stream) : byte_stream =
|
let read_stream_chunked_ ?(buf=Buf_.create()) (bs:byte_stream) : byte_stream =
|
||||||
_debug (fun k->k "body: start reading chunked stream...");
|
_debug (fun k->k "body: start reading chunked stream...");
|
||||||
|
let first = ref true in
|
||||||
let read_next_chunk_len () : int =
|
let read_next_chunk_len () : int =
|
||||||
|
if !first then (
|
||||||
|
first := false
|
||||||
|
) else (
|
||||||
|
let line = Byte_stream.read_line ~buf bs in
|
||||||
|
if String.trim line <> "" then bad_reqf 400 "expected crlf between chunks";
|
||||||
|
);
|
||||||
let line = Byte_stream.read_line ~buf bs in
|
let line = Byte_stream.read_line ~buf bs in
|
||||||
(* parse chunk length, ignore extensions *)
|
(* parse chunk length, ignore extensions *)
|
||||||
let chunk_size = (
|
let chunk_size = (
|
||||||
|
|
@ -370,7 +377,7 @@ module Request = struct
|
||||||
chunk_size
|
chunk_size
|
||||||
in
|
in
|
||||||
let refill = ref true in
|
let refill = ref true in
|
||||||
let bytes = Bytes.make (16 * 4096) ' ' in
|
let bytes = Bytes.make (16 * 4096) ' ' in (* internal buffer, 16kb *)
|
||||||
let offset = ref 0 in
|
let offset = ref 0 in
|
||||||
let len = ref 0 in
|
let len = ref 0 in
|
||||||
let chunk_size = ref 0 in
|
let chunk_size = ref 0 in
|
||||||
|
|
@ -380,7 +387,7 @@ module Request = struct
|
||||||
if !offset >= !len then (
|
if !offset >= !len then (
|
||||||
if !chunk_size = 0 && !refill then (
|
if !chunk_size = 0 && !refill then (
|
||||||
chunk_size := read_next_chunk_len();
|
chunk_size := read_next_chunk_len();
|
||||||
_debug (fun k->k"read next chunk of size %d" !chunk_size);
|
(* _debug (fun k->k"read next chunk of size %d" !chunk_size); *)
|
||||||
);
|
);
|
||||||
offset := 0;
|
offset := 0;
|
||||||
len := 0;
|
len := 0;
|
||||||
|
|
@ -406,7 +413,7 @@ module Request = struct
|
||||||
|
|
||||||
let limit_body_size_ ~max_size (bs:byte_stream) : byte_stream =
|
let limit_body_size_ ~max_size (bs:byte_stream) : byte_stream =
|
||||||
_debug (fun k->k "limit size of body to max-size=%d" max_size);
|
_debug (fun k->k "limit size of body to max-size=%d" max_size);
|
||||||
Byte_stream.limit_size_to ~max_size ~close_rec:true bs
|
Byte_stream.limit_size_to ~max_size ~close_rec:false bs
|
||||||
~too_big:(fun size ->
|
~too_big:(fun size ->
|
||||||
(* read too much *)
|
(* read too much *)
|
||||||
bad_reqf 413
|
bad_reqf 413
|
||||||
|
|
@ -673,8 +680,9 @@ let handle_client_ (self:t) (client_sock:Unix.file_descr) : unit =
|
||||||
let res = Response.make_raw ~code:c s in
|
let res = Response.make_raw ~code:c s in
|
||||||
begin
|
begin
|
||||||
try Response.output_ oc res
|
try Response.output_ oc res
|
||||||
with Sys_error _ -> continue := false
|
with Sys_error _ -> ()
|
||||||
end
|
end;
|
||||||
|
continue := false
|
||||||
| Ok (Some req) ->
|
| Ok (Some req) ->
|
||||||
let res =
|
let res =
|
||||||
try
|
try
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue