Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Returns real remote and local address instead mocked#299

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
nhooyr merged 1 commit intocoder:devfromphotostorm:net-addr
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.

corny and ZackaryWelch reacted with thumbs up emoji
@ZackaryWelch
Copy link

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

}

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

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 anet.Conn and so doesn't have these methods you're checking for.

Copy link
Contributor

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. Seehttps://github.com/nhooyr/websocket/blob/master/internal/test/wstest/pipe.go

Copy link
ContributorAuthor

@photostormphotostormMar 8, 2023
edited
Loading

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
ContributorAuthor

@photostormphotostormMar 8, 2023
edited
Loading

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
Contributor

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
ContributorAuthor

@photostormphotostormMar 8, 2023
edited
Loading

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
Contributor

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
Contributor

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.

@nhooyrnhooyr closed thisMar 7, 2023
@nhooyrnhooyr reopened thisMar 8, 2023
@nhooyr
Copy link
Contributor

Ah I understand, it works server side but would not work with connections fromwebsocket.Dial because there we only get aio.ReadWriteCloser fromnet/http.

@photostorm
Copy link
ContributorAuthor

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
Contributor

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
ContributorAuthor

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

Thanks for your responses.

@nhooyr
Copy link
Contributor

Seehttps://github.com/nhooyr/websocket/blob/14fb98eba64eeb5e9d06a88b98c47ae924ac82b4/dial.go#L128

We don't get anet.Conn fromnet/http when dialing, we only get aio.ReadWriteCloser.

@nhooyrnhooyr changed the base branch frommaster todevOctober 13, 2023 08:11
@nhooyr
Copy link
Contributor

Thanks@photostorm

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
1 more reviewer

@nhooyrnhooyrnhooyr left review comments

Reviewers whose approvals may not affect merge requirements
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@photostorm@ZackaryWelch@nhooyr

[8]ページ先頭

©2009-2025 Movatter.jp