Make gzip compression optional

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2024-08-19 10:56:23 +02:00
parent 9f5882831a
commit e44e077c1f
Signed by: luzifer
SSH key fingerprint: SHA256:/xtE5lCgiRDQr8SLxHMS92ZBlACmATUmF1crK16Ks4E

View file

@ -15,6 +15,7 @@ import (
var ( var (
cfg = struct { cfg = struct {
Gzip bool `flag:"gzip" default:"true" description:"Enable gzip compression"`
Listen string `flag:"listen" default:":3000" description:"Port/IP to listen on"` Listen string `flag:"listen" default:":3000" description:"Port/IP to listen on"`
LogLevel string `flag:"log-level" default:"info" description:"Log level (debug, info, warn, error, fatal)"` LogLevel string `flag:"log-level" default:"info" description:"Log level (debug, info, warn, error, fatal)"`
RootDir string `flag:"root-dir,r" default:"" vardefault:"rootDir" description:"Where to store files / get files from"` RootDir string `flag:"root-dir,r" default:"" vardefault:"rootDir" description:"Where to store files / get files from"`
@ -59,7 +60,9 @@ func main() {
router.PathPrefix("/").Methods(http.MethodPost, http.MethodPut).HandlerFunc(handlePut) router.PathPrefix("/").Methods(http.MethodPost, http.MethodPut).HandlerFunc(handlePut)
var hdl http.Handler = router var hdl http.Handler = router
hdl = httpHelper.GzipHandler(hdl) if cfg.Gzip {
hdl = httpHelper.GzipHandler(hdl)
}
hdl = httpHelper.NewHTTPLogHandlerWithLogger(hdl, logrus.StandardLogger()) hdl = httpHelper.NewHTTPLogHandlerWithLogger(hdl, logrus.StandardLogger())
server := &http.Server{ server := &http.Server{