add websocket compression support

This commit is contained in:
Septs 2016-11-09 17:33:44 +08:00
parent b758b3d9ac
commit fa08b725db

6
ws.go
View File

@ -1,14 +1,12 @@
package gost package gost
import ( import (
//"github.com/ginuerzh/gosocks5"
"crypto/tls" "crypto/tls"
"github.com/golang/glog" "github.com/golang/glog"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
"net" "net"
"net/http" "net/http"
"net/http/httputil" "net/http/httputil"
//"net/url"
"time" "time"
) )
@ -28,6 +26,7 @@ func NewWebsocketServer(base *ProxyServer) *WebsocketServer {
WriteBufferSize: 1024, WriteBufferSize: 1024,
CheckOrigin: func(r *http.Request) bool { return true }, CheckOrigin: func(r *http.Request) bool { return true },
}, },
CompressionSupported: true,
} }
} }
@ -83,6 +82,7 @@ func WebsocketClientConn(url string, conn net.Conn, config *tls.Config) (*Websoc
NetDial: func(net, addr string) (net.Conn, error) { NetDial: func(net, addr string) (net.Conn, error) {
return conn, nil return conn, nil
}, },
CompressionSupported: true,
} }
c, resp, err := dialer.Dial(url, nil) c, resp, err := dialer.Dial(url, nil)
@ -90,7 +90,7 @@ func WebsocketClientConn(url string, conn net.Conn, config *tls.Config) (*Websoc
return nil, err return nil, err
} }
resp.Body.Close() resp.Body.Close()
c.EnableWriteCompression(true)
return &WebsocketConn{conn: c}, nil return &WebsocketConn{conn: c}, nil
} }