mirror of https://github.com/gorilla/websocket.git
Added helper function UnderlyingConn to retrieve net.Conn from Conn objects.
This commit is contained in:
parent
119002ce04
commit
ccad3db007
6
conn.go
6
conn.go
|
@ -765,6 +765,12 @@ func (c *Conn) SetPongHandler(h func(string) error) {
|
||||||
c.handlePong = h
|
c.handlePong = h
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UnderlyingConn returns the internal net.Conn. This can be used to further
|
||||||
|
// modifications to connection specific flags.
|
||||||
|
func (c *Conn) UnderlyingConn() net.Conn {
|
||||||
|
return c.conn
|
||||||
|
}
|
||||||
|
|
||||||
// FormatCloseMessage formats closeCode and text as a WebSocket close message.
|
// FormatCloseMessage formats closeCode and text as a WebSocket close message.
|
||||||
func FormatCloseMessage(closeCode int, text string) []byte {
|
func FormatCloseMessage(closeCode int, text string) []byte {
|
||||||
buf := make([]byte, 2+len(text))
|
buf := make([]byte, 2+len(text))
|
||||||
|
|
10
conn_test.go
10
conn_test.go
|
@ -140,3 +140,13 @@ func TestReadLimit(t *testing.T) {
|
||||||
t.Fatalf("io.Copy() returned %v", err)
|
t.Fatalf("io.Copy() returned %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUnderlyingConn(t *testing.T) {
|
||||||
|
var b1, b2 bytes.Buffer
|
||||||
|
fc := fakeNetConn{Reader: &b1, Writer: &b2}
|
||||||
|
c := newConn(fc, true, 1024, 1024)
|
||||||
|
ul := c.UnderlyingConn()
|
||||||
|
if ul != fc {
|
||||||
|
t.Fatalf("Underlying conn is not what it should be.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue