How to detect the source of HTTP request?

Is there a way to detect the source of HTTP request? for ex: domain name of server which tried to access API endpoint at phoenix server, is this possible?

The Plug.Conn.t does have some fields, one of it is :remote_ip, as I read its description it seems to be what you want:

  • remote_ip - the IP of the client, example: {151, 236, 219, 228}. This field is meant to be overwritten by plugs that understand e.g. the X-Forwarded-For header or HAProxy’s PROXY protocol. It defaults to peer’s IP.
1 Like

Just to mention the Plug.Conn source code where You may find Conn structure in the comments.

UPDATE: @NobbZ I was unable to find Conn docs in Phoenix docs, So I linked to source code… Of course I could not find them, they are in fact in the Plug docs. Here is the link

1 Like

I’d not rely on things that are only described in the source. :remote_ip is actually documented properly. Grabbing random stuff from sources might result in code that relies on private API and breaks with the next update.

1 Like

I’ve found :

  • host - the requested host as a binary, example: ""

I think this is more than enough for me, very useful.

Thats not the source, thats YOU.

ops! bad me…

As I said, :remote_ip is what you are searching for. If you really need a hostname, you’ll have to do a reverse-DNS.

If You want to get more into Conn details, there is this nice blogpost

from Shankardevy, author of Phoenix inside out.

1 Like

Thanks for info