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

x/net/websocket: hacked websocket.go (* Conn)RemoteAddr() to return intuitive value #1636

gopherbot opened this issue Mar 23, 2011 · 5 comments


Copy link

@gopherbot gopherbot commented Mar 23, 2011

by clbanning:

Before filing a bug, please check whether it has been fixed since
the latest release: run "hg pull -u" and retry what you did to
reproduce the problem.  Thanks.

What steps will reproduce the problem?
0. websocket#Conn.RemoteAddr() returns 'host' address for connection.
1. src/pkg/websocket/websocket.go defines (* Conn)RemoteAddr() as:
    func (ws *Conn) RemoteAddr() net.Addr { return WebSocketAddr(ws.Location) }
2. as a result, it returns the same value as (*Conn)LocalAddr() 
3. ws.Location and ws.Orgin are instantiated by websocket.newConn()

What is the expected output?
Intuitively, I thought I'd get the address of the remote end of the connection - the same
as with http.Request.RemoteAddr (and formerly http.ResponseWriter.RemoteAddr()).

What do you see instead?  -- 
I hacked websocket.go to replace RemoteAddr() with:

func (ws *Conn) RemoteAddr() net.Addr {
   if conn, ok := ws.rwc.(net.Conn); ok {
      return conn.RemoteAddr()
   return nil

It now provides the address for the remote end of the connection, as I believe it should.

Which compiler are you using (5g, 6g, 8g, gccgo)?

Which operating system are you using?

Which revision are you using?  (hg identify)
37171a06ed48+ tip

Please provide any additional information below.
Let me know if you'd like this submitted as a Mecurial change.
Copy link

@adg adg commented Mar 24, 2011

Comment 1:

Please submit it as a CL, we can discuss it more easily that way.
Include "Fixes issue #1636." in the description.

Status changed to Accepted.

Copy link

@robpike robpike commented Apr 5, 2011

Comment 2:

Status changed to WaitingForReply.

Copy link

@gopherbot gopherbot commented Apr 26, 2011

Comment 3 by clbanning:

My original post was not clear. 
websocket.Conn.RemoteAddr() does not return the expected value if invoked on the
Listener end of the connection - using *websocket.Conn value passed as the argument for
the websocket handler function.  It does not return the Dialer address, as I had
expected based on the behavior of http.ResponseWriter.RemoteAddr(), etc.
So I guess the real issue is: How can one retrieve the Dialer address for a websocket
connection in a websocket handler function on a server?
Copy link

@gopherbot gopherbot commented Apr 29, 2011

Comment 4 by clbanning:

Now, with *http.Request in websocket.Conn there is no issue.  Should be getting:
Copy link

@rsc rsc commented May 1, 2011

Comment 5:

Status changed to Fixed.

@gopherbot gopherbot added fixed labels May 1, 2011
@mikioh mikioh changed the title hacked websocket.go (* Conn)RemoteAddr() to return intuitive value x/net/websocket: hacked websocket.go (* Conn)RemoteAddr() to return intuitive value Jul 30, 2015
@mikioh mikioh modified the milestone: Unreleased Jul 30, 2015
@golang golang locked and limited conversation to collaborators Aug 5, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.