-
-
Notifications
You must be signed in to change notification settings - Fork 118
exporting underlying Connection #51
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
Conversation
pires
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm trying to understand the issue that drives this change so this feedback is preliminary and assumes the problem can only be addressed by exposing the underlying net.Conn.
From the top of my head, I think a better option here would be for the attribute not to be exported but for an accessor (getter) to be added to Conn, say
func (p *Conn) Raw() net.Conn {
return p.conn
}|
A getter is fine to me. Should I change my pr or will you add it to master? (Raw() needs a comment) |
|
Go ahead! You started the work, after all. Thank you! |
|
Also, can you please add tests that validate casts to, at least, TCPConn? |
|
What do you think? Or change it to Raw() ? |
|
I think this is good as we have other pieces of code that validate casts as well 👍 @emersion do you want to comment? |
pires
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! If no discussion arises, will merge over the weekend.
FWIW, you can upgrade to a specific commit with a need for a new version: |
|
Thank you very much for your contribution, @mschneider82! |
|
Hey. say I called the proxy wrapper's I modified the new test like so, and it no longer pass diff --git a/protocol_test.go b/protocol_test.go
index daadd37..e8601d3 100644
--- a/protocol_test.go
+++ b/protocol_test.go
@@ -487,7 +487,7 @@ func Test_ConnectionCasts(t *testing.T) {
t.Fatalf("err: %v", err)
}
- policyFunc := func(upstream net.Addr) (Policy, error) { return REQUIRE, nil }
+ policyFunc := func(upstream net.Addr) (Policy, error) { return IGNORE, nil }
pl := &Listener{Listener: l, Policy: policyFunc}
@@ -497,7 +497,7 @@ func Test_ConnectionCasts(t *testing.T) {
t.Fatalf("err: %v", err)
}
defer conn.Close()
- conn.Write([]byte("ping"))
+ conn.Write([]byte("pingpong"))
}()
conn, err := pl.Accept()
@@ -506,8 +506,14 @@ func Test_ConnectionCasts(t *testing.T) {
}
defer conn.Close()
+ outbuf := make([]byte, 4)
+ n, err := conn.Read(outbuf)
+ if n != 4 {
+ t.Fatal("err: failed to read from connection wrapper", err)
+ }
+
proxyprotoConn := conn.(*Conn)
- _, ok := proxyprotoConn.TCPConn()
+ tcpconn, ok := proxyprotoConn.TCPConn()
if !ok {
t.Fatal("err: should be a tcp connection")
}
@@ -519,6 +525,11 @@ func Test_ConnectionCasts(t *testing.T) {
if ok {
t.Fatal("err: should be a tcp connection not unix")
}
+
+ n, err = tcpconn.Read(outbuf)
+ if n != 4 {
+ t.Fatal("err: failed to read from underlying connection", err)
+ }
} |
|
Indeed, that sounds correct. We should probably document that. |
|
Also, I guess we could provide a method to drain the internal buffer (however that is done) because someone probably will be interested in that data. |
|
This isn't really possible, once some data has been read from the underlying |
|
Oh yes. of course. I was talking about exposing api to retrieve the data, and let the caller figure out what to do with it. I did not mean to get the data back into the connection. |
|
Users can read the buffered data from the |
|
Well, without calling the internal reader's |
|
Oh, so you mean that you want to get the underlying |
|
Just proxying |
|
I'm worried about people asking to add methods for other The stdlib just exposes the |
this blocks implementing the listener in traefik
traefik/traefik#7320
If you accept it, please create a new version tag, thank you!
closes #50