Skip to content

Commit

Permalink
Remove unused Http_svr.Chunked module
Browse files Browse the repository at this point in the history
Signed-off-by: Rob Hoes <[email protected]>
  • Loading branch information
robhoes committed Oct 17, 2024
1 parent 1683f8f commit 80528e0
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 82 deletions.
72 changes: 0 additions & 72 deletions ocaml/libs/http-lib/http_svr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -713,78 +713,6 @@ let read_body ?limit req bio =
else
Buf_io.really_input_buf ~timeout:Buf_io.infinite_timeout bio length

module Chunked = struct
type t = {
mutable current_size: int
; mutable current_offset: int
; mutable read_headers: bool
; bufio: Buf_io.t
}

let of_bufio bufio =
{current_size= 0; current_offset= 0; bufio; read_headers= true}

let rec read chunk size =
if chunk.read_headers = true then (
(* first get the size, then get the data requested *)
let size =
Buf_io.input_line chunk.bufio
|> Bytes.to_string
|> String.trim
|> Printf.sprintf "0x%s"
|> int_of_string
in
chunk.current_size <- size ;
chunk.current_offset <- 0 ;
chunk.read_headers <- false
) ;
(* read as many bytes from this chunk as possible *)
if chunk.current_size = 0 then
""
else
let bytes_to_read =
min size (chunk.current_size - chunk.current_offset)
in
if bytes_to_read = 0 then
""
else
let data = Bytes.make bytes_to_read '\000' in
Buf_io.really_input chunk.bufio data 0 bytes_to_read ;
(* now update the data structure: *)
if chunk.current_offset + bytes_to_read = chunk.current_size then (
(* finished a chunk: get rid of the CRLF *)
let blank = Bytes.of_string "\000\000" in
Buf_io.really_input chunk.bufio blank 0 2 ;
if Bytes.to_string blank <> "\r\n" then
failwith "chunked encoding error" ;
chunk.read_headers <- true
) else (* partway through a chunk. *)
chunk.current_offset <- chunk.current_offset + bytes_to_read ;
Bytes.unsafe_to_string data ^ read chunk (size - bytes_to_read)
end

let read_chunked_encoding _req bio =
let rec next () =
let size =
Buf_io.input_line bio
(* Strictly speaking need to kill anything past an ';' if present *)
|> Bytes.to_string
|> String.trim
|> Printf.sprintf "0x%s"
|> int_of_string
in
if size = 0 then
Http.End
else
let chunk = Bytes.make size '\000' in
Buf_io.really_input bio chunk 0 size ;
(* Then get rid of the CRLF *)
let blank = Bytes.of_string "\000\000" in
Buf_io.really_input bio blank 0 2 ;
Http.Item (chunk, next)
in
next ()

(* Helpers to determine the client of a call *)

type protocol = Https | Http
Expand Down
10 changes: 0 additions & 10 deletions ocaml/libs/http-lib/http_svr.mli
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,6 @@ exception Socket_not_found

val stop : socket -> unit

module Chunked : sig
type t

val of_bufio : Buf_io.t -> t

val read : t -> int -> string
end

val read_chunked_encoding : Http.Request.t -> Buf_io.t -> bytes Http.ll

(* The rest of this interface needs to be deleted and replaced with Http.Response.* *)

val response_fct :
Expand Down

0 comments on commit 80528e0

Please sign in to comment.