websocket
websocket copied to clipboard
Returns real remote and local address instead mocked
Currently, RemoteAddr() and LocalAddr() are mocked. This change allow the real RemoteAddr() and LocalAddr() to be used.
I would like to get this in if possible. It's the only thing this library lacks from gorilla/websocket.
Going to close as I'm assuming this approach won't work. Leaving the issue open at #327 though so I can figure something out here.
Ah I understand, it works server side but would not work with connections from websocket.Dial
because there we only get a io.ReadWriteCloser
from net/http
.
What is being store with io.ReadWriterClose when using the websocket.Dial? io.ReadWriterClose is just common abstraction. If the io.ReadWriterClose is being used with net.Conn then we know the local address and remote address methods exists. Just because we see io.ReadWriterClose when looking at the code does not hide the ability to access other methods if what being stored there during runtime supports these methods. Can you provide any screenshots of what is being stored there?
I don't fully remember the type but it's not a net.Conn. Grep the net/http.Transport code for protocol upgrade and you'll find it. I'm heading out right now otherwise I'd link you.
I will do exploring with that when I get some time.
Thanks for your responses.
See https://github.com/nhooyr/websocket/blob/14fb98eba64eeb5e9d06a88b98c47ae924ac82b4/dial.go#L128
We don't get a net.Conn
from net/http
when dialing, we only get a io.ReadWriteCloser
.
Thanks @photostorm