websocket icon indicating copy to clipboard operation
websocket copied to clipboard

Returns real remote and local address instead mocked

Open photostorm opened this issue 3 years ago • 1 comments

Currently, RemoteAddr() and LocalAddr() are mocked. This change allow the real RemoteAddr() and LocalAddr() to be used.

photostorm avatar Apr 24 '21 03:04 photostorm

I would like to get this in if possible. It's the only thing this library lacks from gorilla/websocket.

ZackaryWelch avatar May 05 '22 14:05 ZackaryWelch

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.

nhooyr avatar Mar 07 '23 15:03 nhooyr

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.

nhooyr avatar Sep 28 '23 14:09 nhooyr

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?

photostorm avatar Sep 28 '23 20:09 photostorm

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.

nhooyr avatar Sep 28 '23 20:09 nhooyr

I will do exploring with that when I get some time.

Thanks for your responses.

photostorm avatar Sep 29 '23 00:09 photostorm

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.

nhooyr avatar Oct 13 '23 08:10 nhooyr

Thanks @photostorm

nhooyr avatar Oct 13 '23 08:10 nhooyr