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

Optional interface for a ResponseWriter to expose Conns #1487

Open
jefferai opened this issue Oct 3, 2023 · 3 comments
Open

Optional interface for a ResponseWriter to expose Conns #1487

jefferai opened this issue Oct 3, 2023 · 3 comments

Comments

@jefferai
Copy link

jefferai commented Oct 3, 2023

Hello, and thanks for a great library!

It would be useful to me if I can get access to the underlying connections in a response object. I only want to do some read-only introspection (I'm aware that actually reading/writing from the conns would be rather dangerous).

It is fairly trivial to do this in a way that won't break backwards compatibility by introducing an optional interface that can be satisfied with one or two functions (depending on if it's one function for tcp and one for udp or if the same function returns both). I've tested this locally and it's a very small change that works well.

Would this be something that would be accepted in a PR? If not, is there another way to get the connection related to an incoming message?

Thanks!

@tmthrgd
Copy link
Collaborator

tmthrgd commented Oct 31, 2023

crypto/tls has let you do this since go1.18 so it doesn't seem like the worst idea (https://pkg.go.dev/crypto/tls#Conn.NetConn). Though they have the benefit of always having a TCP connection (except when using QUIC).

Out of interest, what in particular are you trying to get from the underlying connection?

@jefferai
Copy link
Author

jefferai commented Nov 1, 2023

So for what it's worth here's one way to slice it, although there are other ways it can be done (or with other naming)

jefferai@876d499

Basically I need access to retrieve the local/remote addresses of the connections.

@jefferai
Copy link
Author

jefferai commented Nov 1, 2023

For more explanation: some platforms (cough, Windows, cough) do not allow you to firewall anything on localhost so if you want to perform any introspection or security controls you have to do it yourself, so having connection information is extremely useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants