Skip to content

Commit 78cf1bc

Browse files
authored
Changed the method name UnderlyingConn to NetConn to align the methods names with Go 1.18 standard library (gorilla#773)
1 parent 69d0eb9 commit 78cf1bc

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

conn.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,8 +1189,16 @@ func (c *Conn) SetPongHandler(h func(appData string) error) {
11891189
c.handlePong = h
11901190
}
11911191

1192+
// NetConn returns the underlying connection that is wrapped by c.
1193+
// Note that writing to or reading from this connection directly will corrupt the
1194+
// WebSocket connection.
1195+
func (c *Conn) NetConn() net.Conn {
1196+
return c.conn
1197+
}
1198+
11921199
// UnderlyingConn returns the internal net.Conn. This can be used to further
11931200
// modifications to connection specific flags.
1201+
// Deprecated: Use the NetConn method.
11941202
func (c *Conn) UnderlyingConn() net.Conn {
11951203
return c.conn
11961204
}

conn_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ func TestAddrs(t *testing.T) {
562562
}
563563
}
564564

565-
func TestUnderlyingConn(t *testing.T) {
565+
func TestDeprecatedUnderlyingConn(t *testing.T) {
566566
var b1, b2 bytes.Buffer
567567
fc := fakeNetConn{Reader: &b1, Writer: &b2}
568568
c := newConn(fc, true, 1024, 1024, nil, nil, nil)
@@ -572,6 +572,16 @@ func TestUnderlyingConn(t *testing.T) {
572572
}
573573
}
574574

575+
func TestNetConn(t *testing.T) {
576+
var b1, b2 bytes.Buffer
577+
fc := fakeNetConn{Reader: &b1, Writer: &b2}
578+
c := newConn(fc, true, 1024, 1024, nil, nil, nil)
579+
ul := c.NetConn()
580+
if ul != fc {
581+
t.Fatalf("Underlying conn is not what it should be.")
582+
}
583+
}
584+
575585
func TestBufioReadBytes(t *testing.T) {
576586
// Test calling bufio.ReadBytes for value longer than read buffer size.
577587

server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func TestBufioReuse(t *testing.T) {
111111
if reuse := c.br == br; reuse != tt.reuse {
112112
t.Errorf("%d: buffered reader reuse=%v, want %v", i, reuse, tt.reuse)
113113
}
114-
writeBuf := bufioWriterBuffer(c.UnderlyingConn(), bw)
114+
writeBuf := bufioWriterBuffer(c.NetConn(), bw)
115115
if reuse := &c.writeBuf[0] == &writeBuf[0]; reuse != tt.reuse {
116116
t.Errorf("%d: write buffer reuse=%v, want %v", i, reuse, tt.reuse)
117117
}

0 commit comments

Comments
 (0)