Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returns real remote and local address instead mocked #299

Merged
merged 1 commit into from
Oct 13, 2023

Conversation

photostorm
Copy link
Contributor

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

@photostorm photostorm requested a review from nhooyr as a code owner April 24, 2021 03:24
@ZackaryWelch
Copy link

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

netconn_notjs.go Outdated
}

func (c *netConn) RemoteAddr() net.Addr {
if ra, ok := c.c.rwc.(LocalRemoteAddr); ok {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how this could work? Have you tested this? c.c.rwc is not a net.Conn and so doesn't have these methods you're checking for.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It only works in tests because the tests don't use a real http transport/server, they're using my pipe abstraction. See https://github.com/nhooyr/websocket/blob/master/internal/test/wstest/pipe.go

Copy link
Contributor Author

@photostorm photostorm Mar 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works fine. Its check the reader/writer if it also has RemoteAddr() and LocalAddr() defined. It is not checking if it net.conn.

Copy link
Contributor Author

@photostorm photostorm Mar 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nhooyr Here is example of something similar to what I did:
https://github.com/golang/go/blob/master/src/io/io.go#L408

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested this in production? There's no RemoteAddr or LocalAddr on the bufio.ReadWriter returned to us from the transport.

Copy link
Contributor Author

@photostorm photostorm Mar 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This the echo example.
Screen Shot 2023-03-08 at 12 10 06 PM

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok now I'm super confused I'll have to look into how that's possible lol

@nhooyr
Copy link
Owner

nhooyr commented Mar 7, 2023

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 nhooyr closed this Mar 7, 2023
@nhooyr nhooyr reopened this Mar 8, 2023
@nhooyr
Copy link
Owner

nhooyr commented Sep 28, 2023

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.

@photostorm
Copy link
Contributor Author

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?

@nhooyr
Copy link
Owner

nhooyr commented Sep 28, 2023

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.

@photostorm
Copy link
Contributor Author

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

Thanks for your responses.

@nhooyr
Copy link
Owner

nhooyr commented Oct 13, 2023

See

rwc, ok := respBody.(io.ReadWriteCloser)

We don't get a net.Conn from net/http when dialing, we only get a io.ReadWriteCloser.

@nhooyr nhooyr changed the base branch from master to dev October 13, 2023 08:11
@nhooyr nhooyr merged commit 61942a4 into nhooyr:dev Oct 13, 2023
1 of 3 checks passed
@nhooyr
Copy link
Owner

nhooyr commented Oct 13, 2023

Thanks @photostorm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants