mirage / ocaml-cohttp

An OCaml library for HTTP clients and servers using Lwt or Async
Other
703 stars 173 forks source link

Setting the bind address and port is too hard #543

Open copy opened 7 years ago

copy commented 7 years ago

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.

rgrinberg commented 7 years ago

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.