1
0
mirror of https://github.com/tinode/chat.git synced 2025-03-15 18:53:05 +00:00

make websocket per-message compression optional

This commit is contained in:
or-else
2023-03-29 09:27:39 -07:00
parent 1466226594
commit e27e4ef4a7
3 changed files with 14 additions and 1 deletions

@ -159,7 +159,7 @@ func wsWrite(ws *websocket.Conn, mt int, msg any) error {
var upgrader = websocket.Upgrader{ var upgrader = websocket.Upgrader{
ReadBufferSize: 1024, ReadBufferSize: 1024,
WriteBufferSize: 1024, WriteBufferSize: 1024,
EnableCompression: true, EnableCompression: globals.wsCompression,
// Allow connections from any Origin // Allow connections from any Origin
CheckOrigin: func(r *http.Request) bool { return true }, CheckOrigin: func(r *http.Request) bool { return true },
} }

@ -195,6 +195,9 @@ var globals struct {
// ICE servers config (video calling) // ICE servers config (video calling)
iceServers []iceServer iceServers []iceServer
// Websocket per-message compression negotiation is enabled.
wsCompression bool
} }
// Credential validator config. // Credential validator config.
@ -245,6 +248,9 @@ type configType struct {
ApiPath string `json:"api_path"` ApiPath string `json:"api_path"`
// Cache-Control value for static content. // Cache-Control value for static content.
CacheControl int `json:"cache_control"` CacheControl int `json:"cache_control"`
// If true, do not attempt to negotiate websocket per message compression (RFC 7692.4).
// It should be disabled (set to true) if you are using MSFT IIS as reverse proxy.
WSCompressionDisabled bool `json:"ws_compression_disabled"`
// Address:port to listen for gRPC clients. If blank gRPC support will not be initialized. // Address:port to listen for gRPC clients. If blank gRPC support will not be initialized.
// Could be overridden from the command line with --grpc_listen. // Could be overridden from the command line with --grpc_listen.
GrpcListen string `json:"grpc_listen"` GrpcListen string `json:"grpc_listen"`
@ -545,6 +551,9 @@ func main() {
globals.defaultCountryCode = defaultCountryCode globals.defaultCountryCode = defaultCountryCode
} }
// Websocket compression.
globals.wsCompression = !config.WSCompressionDisabled
if config.Media != nil { if config.Media != nil {
if config.Media.UseHandler == "" { if config.Media.UseHandler == "" {
config.Media = nil config.Media = nil

@ -15,6 +15,10 @@
// Cache-Control header for static content in seconds. 39600 is 11 hours. // Cache-Control header for static content in seconds. 39600 is 11 hours.
"cache_control": 39600, "cache_control": 39600,
// If true, do not attempt to negotiate websocket per message compression (RFC 7692.4).
// It should be disabled (set to true) if you are using MSFT IIS as a reverse proxy.
"ws_compression_disabled": false,
// URL path for mounting the directory with static files. // URL path for mounting the directory with static files.
"static_mount": "/", "static_mount": "/",