ocaml-cohttp icon indicating copy to clipboard operation
ocaml-cohttp copied to clipboard

Setting the bind address and port is too hard

Open copy opened this issue 8 years ago • 1 comments

A usability issue: Setting the bind address and port of a Cohttp_lwt_unix.Server currently involves calling a function from Cohttp_lwt_unix.Client, searching Conduit and unnecessary lwt operations (at least for a TCP server). See below.

  let%lwt ctx = Conduit_lwt_unix.init ~src:"127.0.0.1" () in
  let ctx = Cohttp_lwt_unix.Client.custom_ctx ~ctx () in
  Server.create ~ctx ~mode:(`TCP (`Port 8080))

Instead, a helper function Cohttp_lwt_unix.Server.create_tcp : ?port:int -> ?bind_address:Ipaddr.t -> … or similar should be provided.

copy avatar Apr 09 '17 23:04 copy

Agreed. This is all caused by the fact that the server piece is heavily tied to conduit. Imo, we should have a simpler server layer that's based on Lwt_io.establish_server and perhaps provide a direct callback that allows users to use whatever server implementation they want. Using a conduit server should be completely optional.

rgrinberg avatar Apr 10 '17 03:04 rgrinberg