Skip to content

Commit

Permalink
lxd: enable server side gzip compression on all API routes
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel Mougard <gabriel.mougard@canonical.com>
  • Loading branch information
gabrielmougard committed Mar 18, 2024
1 parent f88e17e commit 26e61c0
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lxd/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ func restServer(d *Daemon) *http.Server {
mux.SkipClean(true)
mux.UseEncodedPath() // Allow encoded values in path segments.

// Enable gzip compression globally.
mux.Use(func(next http.Handler) http.Handler {
return gorillaHandlers.CompressHandler(next)
})

uiPath := os.Getenv("LXD_UI")
uiEnabled := uiPath != "" && shared.PathExists(uiPath)
if uiEnabled {
Expand All @@ -86,10 +91,7 @@ func restServer(d *Daemon) *http.Server {
uiHandler.ServeHTTP(w, r)
})

// Enable gzip compression
uiHandlerWithGzip := gorillaHandlers.CompressHandler(uiHandlerWithSecurity)

mux.PathPrefix("/ui/").Handler(uiHandlerWithGzip)
mux.PathPrefix("/ui/").Handler(uiHandlerWithSecurity)
mux.HandleFunc("/ui", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/ui/", http.StatusMovedPermanently)
})
Expand Down

0 comments on commit 26e61c0

Please sign in to comment.