Skip to content

Commit

Permalink
cohttp-eio: Debug body encoding.
Browse files Browse the repository at this point in the history
  • Loading branch information
mefyl committed Jan 4, 2024
1 parent 5711091 commit afd2d23
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cohttp-eio/src/server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ let write output response body =
let () =
Io.Response.write
(fun writer ->
let () = Logs.debug (fun m -> m "send body") in
let () =
Logs.debug (fun m ->
(m "send body (%a)" Cohttp.Transfer.pp_encoding response.encoding
[@ocaml.warning "-3"]))
in
flow_to_writer body writer Io.Response.write_body)
response output
in
Expand Down
5 changes: 5 additions & 0 deletions cohttp/src/transfer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ open Sexplib0.Sexp_conv
type encoding = Http.Transfer.encoding = Chunked | Fixed of int64 | Unknown
[@@deriving sexp]

let pp_encoding fmt = function
| Chunked -> Format.pp_print_string fmt "chunked"
| Fixed size -> Format.fprintf fmt "fixed %Ld" size
| Unknown -> Format.pp_print_string fmt "unknown"

type chunk = Chunk of string | Final_chunk of string | Done [@@deriving sexp]

let string_of_encoding = function
Expand Down
3 changes: 3 additions & 0 deletions cohttp/src/transfer.mli
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ type encoding = Http.Transfer.encoding =
| Unknown (** unknown body size, which leads to best-effort *)
[@@deriving sexp]

val pp_encoding : Format.formatter -> encoding -> unit
(** Human-readable output. *)

(** A chunk of body that also signals if there to more to arrive *)
type chunk =
| Chunk of string (** chunk of data and not the end of stream *)
Expand Down

0 comments on commit afd2d23

Please sign in to comment.