From b4e6052444a3b36bc8c084734e068bc4d17faf12 Mon Sep 17 00:00:00 2001 From: Shu Takayama Date: Mon, 19 Aug 2019 19:01:19 +0900 Subject: [PATCH 1/2] compression --- handler/handler.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/handler/handler.go b/handler/handler.go index 8822188..e96b3fa 100644 --- a/handler/handler.go +++ b/handler/handler.go @@ -49,9 +49,10 @@ func New( logger *zap.Logger) (*Handler, error) { upgrader := websocket.Upgrader{ - ReadBufferSize: BufferSize, - WriteBufferSize: BufferSize, - HandshakeTimeout: handshakeTimeout, + EnableCompression: true, + ReadBufferSize: BufferSize, + WriteBufferSize: BufferSize, + HandshakeTimeout: handshakeTimeout, CheckOrigin: func(r *http.Request) bool { return true }, From a6a2da3287055883a026765de259bc115b77ceba Mon Sep 17 00:00:00 2001 From: Shu Takayama Date: Tue, 27 Aug 2019 20:04:32 +0900 Subject: [PATCH 2/2] add enable_compression option --- handler/handler.go | 20 +++++++++++--------- wsgate-server.go | 24 +++++++++++++----------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/handler/handler.go b/handler/handler.go index e96b3fa..44d90d8 100644 --- a/handler/handler.go +++ b/handler/handler.go @@ -28,14 +28,15 @@ var ( // Handler handlers type Handler struct { - logger *zap.Logger - upgrader websocket.Upgrader - dialTimeout time.Duration - writeTimeout time.Duration - mp *mapping.Mapping - pk *publickey.Publickey - dumpTCP uint - sq *seq.Seq + logger *zap.Logger + upgrader websocket.Upgrader + dialTimeout time.Duration + writeTimeout time.Duration + enableCompression bool + mp *mapping.Mapping + pk *publickey.Publickey + dumpTCP uint + sq *seq.Seq } // New new handler @@ -43,13 +44,14 @@ func New( handshakeTimeout time.Duration, dialTimeout time.Duration, writeTimeout time.Duration, + enableCompression bool, mp *mapping.Mapping, pk *publickey.Publickey, dumpTCP uint, logger *zap.Logger) (*Handler, error) { upgrader := websocket.Upgrader{ - EnableCompression: true, + EnableCompression: enableCompression, ReadBufferSize: BufferSize, WriteBufferSize: BufferSize, HandshakeTimeout: handshakeTimeout, diff --git a/wsgate-server.go b/wsgate-server.go index e3bf4a0..25fa706 100644 --- a/wsgate-server.go +++ b/wsgate-server.go @@ -23,17 +23,18 @@ import ( var ( // Version wsgate-server version - Version string - showVersion = flag.Bool("version", false, "show version") - listen = flag.String("listen", "127.0.0.1:8086", "Address to listen to.") - handshakeTimeout = flag.Duration("handshake_timeout", 10*time.Second, "Handshake timeout.") - dialTimeout = flag.Duration("dial_timeout", 10*time.Second, "Dial timeout.") - writeTimeout = flag.Duration("write_timeout", 10*time.Second, "Write timeout.") - shutdownTimeout = flag.Duration("shutdown_timeout", 86400*time.Second, "timeout to wait for all connections to be closed") - mapFile = flag.String("map", "", "path and proxy host mapping file") - publicKeyFile = flag.String("public-key", "", "public key for verifying JWT auth header") - jwtFreshness = flag.Duration("jwt-freshness", 3600*time.Second, "time in seconds to allow generated jwt tokens") - dumpTCP = flag.Uint("dump-tcp", 0, "Dump TCP. 0 = disable, 1 = src to dest, 2 = both") + Version string + showVersion = flag.Bool("version", false, "Show version") + listen = flag.String("listen", "127.0.0.1:8086", "Address to listen to") + handshakeTimeout = flag.Duration("handshake_timeout", 10*time.Second, "Handshake timeout") + dialTimeout = flag.Duration("dial_timeout", 10*time.Second, "Dial timeout") + writeTimeout = flag.Duration("write_timeout", 10*time.Second, "Write timeout") + shutdownTimeout = flag.Duration("shutdown_timeout", 86400*time.Second, "Timeout to wait for all connections to be closed") + enableCompression = flag.Bool("enable_compression", false, "To enable WebSocket Per-Message Compression Extensions (RFC 7692)") + mapFile = flag.String("map", "", "Path and proxy host mapping file") + publicKeyFile = flag.String("public-key", "", "Public key for verifying JWT auth header") + jwtFreshness = flag.Duration("jwt-freshness", 3600*time.Second, "Time in seconds to allow generated jwt tokens") + dumpTCP = flag.Uint("dump-tcp", 0, "Dump TCP. 0 = disable, 1 = src to dest, 2 = both") ) func printVersion() { @@ -68,6 +69,7 @@ func main() { *handshakeTimeout, *dialTimeout, *writeTimeout, + *enableCompression, mp, pk, *dumpTCP,