2

Is it possible to get the remote IP address at the conduit or cohttp level? I've tried digging though the source code, but it seems to be buried under several layers of abstraction. I'm writing rest services that I plan to deploy as unikernels and logging the IP address of the requester is a security requirement.

I'm using cohttp and would want to be able to do this in both unix (for testing) and xen (for deployment). I could put in conditional code for the two environments if necessary.

Juan Chanco
  • 157
  • 6

1 Answers1

3

I modified the example in cohttp's readme to:

open Sexplib
[...]

  let callback (flow, _connection_id) req body =
    Conduit_lwt_unix.sexp_of_flow flow |> Sexp.to_string |> print_endline;

When I connected from localhost, it printed:

(TCP((fd <opaque>)(ip(V4 127.0.0.1))(port 62168)))

(figuring this out isn't too obvious; I just replaced the _conn in the example with () and followed the type errors...)

Thomas Leonard
  • 7,068
  • 2
  • 36
  • 40
  • This is very helpful and gets me much closer, thanks! I'm now trying to figure out how to get it to work in mirage. Flow in conduit_mirage/cohttp_mirage seems to delegate to a V1_LWT.FLOW implementation and I can't find a sexp conversion for it. I'm continuing to dig. – Juan Chanco Sep 06 '16 at 22:58