Skip to content

Commit

Permalink
Merge pull request #40 from alberts-s/add-compression
Browse files Browse the repository at this point in the history
Add support for Websocket compression
  • Loading branch information
d-Rickyy-b authored Jul 14, 2024
2 parents 2b5971c + 2457962 commit 6adc0e5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]
### Added
- Support for websocket compression - disabled by default (#40)
- Support for non-browsers by implementing server initiated heartbeats (#39)
### Changed
### Fixed
Expand Down
1 change: 1 addition & 0 deletions config.sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ webserver:
domains_only_url: "/domains-only"
cert_path: ""
cert_key_path: ""
compression_enabled: false

prometheus:
enabled: true
Expand Down
9 changes: 5 additions & 4 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ type ServerConfig struct {

type Config struct {
Webserver struct {
ServerConfig `yaml:",inline"`
FullURL string `yaml:"full_url"`
LiteURL string `yaml:"lite_url"`
DomainsOnlyURL string `yaml:"domains_only_url"`
ServerConfig `yaml:",inline"`
FullURL string `yaml:"full_url"`
LiteURL string `yaml:"lite_url"`
DomainsOnlyURL string `yaml:"domains_only_url"`
CompressionEnabled bool `yaml:"compression_enabled"`
}
Prometheus struct {
ServerConfig `yaml:",inline"`
Expand Down
9 changes: 7 additions & 2 deletions internal/web/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

var (
ClientHandler = BroadcastManager{}
upgrader = websocket.Upgrader{} // use default options
upgrader websocket.Upgrader
)

type WebServer struct {
Expand Down Expand Up @@ -248,7 +248,8 @@ func NewMetricsServer(networkIf string, port int, certPath, keyPath string) *Web
}

// NewWebsocketServer starts a new webserver and initialized it with the necessary routes.
// It also starts the broadcaster in ClientHandler as a background job.
// It also starts the broadcaster in ClientHandler as a background job and takes care of
// setting up websocket.Upgrader.
func NewWebsocketServer(networkIf string, port int, certPath, keyPath string) *WebServer {
server := &WebServer{
networkIf: networkIf,
Expand All @@ -258,6 +259,10 @@ func NewWebsocketServer(networkIf string, port int, certPath, keyPath string) *W
keyPath: keyPath,
}

upgrader = websocket.Upgrader{
EnableCompression: *config.AppConfig.Webserver.CompressionEnabled,
}

if config.AppConfig.Webserver.RealIP {
server.routes.Use(middleware.RealIP)
}
Expand Down

0 comments on commit 6adc0e5

Please sign in to comment.