vbmithr / ocaml-websocket

Websocket library for OCaml
ISC License
162 stars 44 forks source link

Expose client IP address #70

Closed copy closed 7 years ago

copy commented 7 years ago

Websocket_lwt.establish_server has the following signature:

val establish_server :
    ?timeout:int ->
    ?stop:unit Lwt.t ->
    ?random_string:Rng.t ->
    ctx:Conduit_lwt_unix.ctx ->
    mode:Conduit_lwt_unix.server ->
    (int -> Cohttp.Request.t -> (unit -> Frame.t Lwt.t) -> (Frame.t -> unit Lwt.t) -> unit Lwt.t) ->
    unit Lwt.t

I would like to get the connecting clients IP address, but the callback doesn't provide this info. It could be provided by passing the Conduit flow or the IP address directly.

If we're already breaking the signature, we could also make a new private type of which a value is passed to the callback, which contains all the information needed to send, receive and the other things, i.e.:

module Connected_client : sig
  type t
  val send : t -> Frame.t -> unit Lwt.t
  val request : t -> Cohttp.Request.t
  val ip : t -> Ipaddr.t
  (* … *)
end

val establish_server :
    ?timeout:int ->
    ?stop:unit Lwt.t ->
    ?random_string:Rng.t ->
    ctx:Conduit_lwt_unix.ctx ->
    mode:Conduit_lwt_unix.server ->
    (Connected_client.t -> unit Lwt.t) ->
    unit Lwt.t
vbmithr commented 7 years ago

Since there are already four arguments to the callback, your proposal looks reasonable to me. Feel free to implement it.