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

Closed
gopherbot opened this issue Mar 23, 2011 · 5 comments

Comments

@gopherbot
Copy link

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)?
8g

Which operating system are you using?
darwin

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.
@adg
Copy link
Contributor

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.

@robpike
Copy link
Contributor

robpike commented Apr 5, 2011

Comment 2:

Status changed to WaitingForReply.

@gopherbot
Copy link
Author

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?

@gopherbot
Copy link
Author

Comment 4 by clbanning:

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

@rsc
Copy link
Contributor

rsc commented May 1, 2011

Comment 5:

Status changed to Fixed.

@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.
Projects
None yet
Development

No branches or pull requests

5 participants