-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
net/http: add Request.LocalAddr #6732
Comments
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 luke@hydrantlabs.org: 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 |
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. |
…ved on This adds a context key named LocalAddrContextKey (for now, see #15229) to let users access the net.Addr of the net.Listener that accepted the connection that sent an HTTP request. This is similar to ServerContextKey which provides access to the *Server. (A Server may have multiple Listeners) Fixes #6732 Change-Id: I74296307b68aaaab8df7ad4a143e11b5227b5e62 Reviewed-on: https://go-review.googlesource.com/22672 Reviewed-by: Andrew Gerrand <adg@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
With Go 1.7, there is a That makes this feature somewhat useless. I think the desired behavior would be to return the actual WorkaroundHijack the |
by joijoi360:
The text was updated successfully, but these errors were encountered: