How to access http headers in Phoenix socket?

I’ve figured it out: it’s the Cowboy’s process :cowboy_clear.connection_process/4. You can get its PID from the socket’s connect/3 like this:

{:links, [pid]} = Process.info(self(), :links)

Then you create a timer to disconnect the socket using something like:

timer_ref = Process.send_after(pid, %Broadcast{event: "disconnect"}, 3000)

Save the timer_ref in the socket’s assigns and cancel it later in the Channel’s join, like:

Process.cancel_timer(socket.assigns.auth_timer)
1 Like