Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impl: compression #8

Merged
merged 2 commits into from
Aug 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,33 @@ 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
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{
ReadBufferSize: BufferSize,
WriteBufferSize: BufferSize,
HandshakeTimeout: handshakeTimeout,
EnableCompression: enableCompression,
ReadBufferSize: BufferSize,
WriteBufferSize: BufferSize,
HandshakeTimeout: handshakeTimeout,
CheckOrigin: func(r *http.Request) bool {
return true
},
Expand Down
24 changes: 13 additions & 11 deletions wsgate-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -68,6 +69,7 @@ func main() {
*handshakeTimeout,
*dialTimeout,
*writeTimeout,
*enableCompression,
mp,
pk,
*dumpTCP,
Expand Down