-
Notifications
You must be signed in to change notification settings - Fork 29
/
proxy.go
56 lines (46 loc) · 936 Bytes
/
proxy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"context"
"github.com/gorilla/websocket"
"net/http"
)
const (
incomingBufferSize = 10 * 1024 * 1024
outgoingBufferSize = 25 * 1024 * 1024
)
var wsUpgrader = &websocket.Upgrader{
ReadBufferSize: incomingBufferSize,
WriteBufferSize: outgoingBufferSize,
CheckOrigin: func(r *http.Request) bool {
return true
},
}
var wsDialer = &websocket.Dialer{
ReadBufferSize: outgoingBufferSize,
WriteBufferSize: incomingBufferSize,
}
func proxyWS(ctxt context.Context, stream chan *protocolMessage, in, out *websocket.Conn, errc chan error) {
var mt int
var buf []byte
var err error
for {
select {
default:
mt, buf, err = in.ReadMessage()
if err != nil {
errc <- err
return
}
if msg, derr := decodeMessage(buf); derr == nil {
stream <- msg
}
err = out.WriteMessage(mt, buf)
if err != nil {
errc <- err
return
}
case <-ctxt.Done():
return
}
}
}