Skip to content

Commit 6facb74

Browse files
committed
Get the raw connection
1 parent efaa0f3 commit 6facb74

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

conn.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
// This handler is compatible with io.Writer.
1515
type Conn struct {
1616
c net.Conn
17+
br *bufio.Reader
1718
bw *bufio.Writer
1819

1920
input chan *Frame
@@ -92,6 +93,7 @@ func (c *Conn) reset(conn net.Conn) {
9293
c.MaxPayloadSize = DefaultPayloadSize
9394
c.userValues = make(map[string]interface{})
9495
c.c = conn
96+
c.br = bufio.NewReader(conn)
9597
c.bw = bufio.NewWriter(conn)
9698
}
9799

@@ -105,7 +107,7 @@ func (c *Conn) readLoop() {
105107
// if c.ReadTimeout != 0 {
106108
// }
107109

108-
_, err := fr.ReadFrom(c.c)
110+
_, err := fr.ReadFrom(c.br)
109111
if err != nil {
110112
select {
111113
case c.errch <- closeError{err: err}:

server.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,12 @@ func (s *Server) Upgrade(ctx *fasthttp.RequestCtx) {
194194
})
195195

196196
ctx.Hijack(func(c net.Conn) {
197+
if nc, ok := c.(interface {
198+
UnsafeConn() net.Conn
199+
}); ok {
200+
c = nc.UnsafeConn()
201+
}
202+
197203
conn := acquireConn(c)
198204
conn.id = atomic.AddUint64(&s.nextID, 1)
199205
// establishing default options

0 commit comments

Comments
 (0)