by joijoi360:
Before filing a bug, please check whether it has been fixed since the latest release. Search the issue tracker and check that you're running the latest version of Go: Run "go version" and compare against http://golang.org/doc/devel/release.html If a newer version of Go exists, install it and retry what you did to reproduce the problem. Thanks. What steps will reproduce the problem? If possible, include a link to a program on play.golang.org. 1.http://play.golang.org/p/-DIhMc_XjT 2.http://play.golang.org/p/55V_nyuKPR(There is revised code net/http/server.go) 3.http://play.golang.org/p/jroO70Cno8(There is revised code net/http/request.go) What is the expected output? Request.LocalAddr What do you see instead? The LocalAddr isn't here. Which compiler are you using (5g, 6g, 8g, gccgo)? gccgo Which operating system are you using? os x 10.9 Which version are you using? (run 'go version') go version go1.1.2 darwin/amd64 Please provide any additional information below. because the network line and the operators do IP,there isn't LocalAddr in Rep resource.requiring different
1.http://play.golang.org/p/-DIhMc_XjT 2.http://play.golang.org/p/55V_nyuKPR (There is revised code net/http/server.go) 3.http://play.golang.org/p/jroO70Cno8 (There is revised code net/http/request.go)
Comment 8 by [email protected]:
I am in need of this feature. In fact, I am currently running the same server bound to different ips to get around this issue.
I need this as well. I have a usecase where I want to return (very) slightly modified response based on which IP the client used to connect to. And for a particular reason I would like to use the same process to serve all IP. I could perhaps get away with registering multiple servers each listening to a different IP and using custom handler for each server... but it sounds ugly.
I also need this feature.
Sorry, I'm going to close this issue without action. There are few enough cases where this is required that I don't think it's worth complicating the net/http package API and making the Request struct larger.
There's an easy enough workaround: run a Server on each interface with a Handler that sets a magic HTTP request header and then delegates to a shared root handler.
Well, the reason I needed this is to detect loops in a proxy. Using ConnState works for me.
Listening on 0.0.0.0 and then using LocalAddr for ACLs/partitioning traffic is an extremely efficient, convenient, and common pattern among unix servers. It's a real shame net/http can't do it. In my case, my program listens on hundreds of dynamic IPs and it's a real problem not having access to LocalAddr. Just another +1. Thanks for all your hard work.
CL https://golang.org/cl/22672 mentions this issue.
With Go 1.7, there is a httpRequest.Context().Value(http.LocalAddrContextKey).(net.Addr), but this value is always the same listen address as passed to http.ListenAndServe. So for a server having multiple interfaces/local addresses, and starting a Go http server on :8000, it will always be [::]:8000, regardless of which server address the client connected to.
That makes this feature somewhat useless.
I think the desired behavior would be to return the actual net.Conn.LocalAddr() for the accepted connection. This would return different values for clients connecting to different local addresses on the same server having a single http.Sever listening on 0.0.0.0/::.
Hijack the http.ResponseWriter and then get at the conn.LocalAddr()
@SpComb, thanks for the note, but in general comments on closed issues are where action items go to die. I've opened #18686 so this can actually be tracked.
Most helpful comment
@SpComb, thanks for the note, but in general comments on closed issues are where action items go to die. I've opened #18686 so this can actually be tracked.