add websocket compression support (#56)
This commit is contained in:
parent
1a88ca09f5
commit
e22229b5b1
11
ws.go
11
ws.go
@ -25,8 +25,8 @@ func NewWebsocketServer(base *ProxyServer) *WebsocketServer {
|
||||
ReadBufferSize: 1024,
|
||||
WriteBufferSize: 1024,
|
||||
CheckOrigin: func(r *http.Request) bool { return true },
|
||||
EnableCompression: true,
|
||||
},
|
||||
CompressionSupported: true,
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,10 +79,10 @@ func WebsocketClientConn(url string, conn net.Conn, config *tls.Config) (*Websoc
|
||||
WriteBufferSize: 1024,
|
||||
TLSClientConfig: config,
|
||||
HandshakeTimeout: DialTimeout,
|
||||
EnableCompression: true,
|
||||
NetDial: func(net, addr string) (net.Conn, error) {
|
||||
return conn, nil
|
||||
},
|
||||
CompressionSupported: true,
|
||||
}
|
||||
|
||||
c, resp, err := dialer.Dial(url, nil)
|
||||
@ -90,11 +90,11 @@ func WebsocketClientConn(url string, conn net.Conn, config *tls.Config) (*Websoc
|
||||
return nil, err
|
||||
}
|
||||
resp.Body.Close()
|
||||
c.EnableWriteCompression(true)
|
||||
return &WebsocketConn{conn: c}, nil
|
||||
}
|
||||
|
||||
func WebsocketServerConn(conn *websocket.Conn) *WebsocketConn {
|
||||
conn.EnableWriteCompression(true)
|
||||
return &WebsocketConn{
|
||||
conn: conn,
|
||||
}
|
||||
@ -106,17 +106,12 @@ func (c *WebsocketConn) Read(b []byte) (n int, err error) {
|
||||
}
|
||||
n = copy(b, c.rb)
|
||||
c.rb = c.rb[n:]
|
||||
|
||||
//log.Println("ws r:", n)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (c *WebsocketConn) Write(b []byte) (n int, err error) {
|
||||
err = c.conn.WriteMessage(websocket.BinaryMessage, b)
|
||||
n = len(b)
|
||||
//log.Println("ws w:", n)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user