webdav: add compression support

Fixes #295
This commit is contained in:
Nicola Murino 2021-02-04 09:06:41 +01:00
parent a219d25cac
commit 17a42a0c11
No known key found for this signature in database
GPG key ID: 2F1FB59433D5A8CB

View file

@ -14,6 +14,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/go-chi/chi/middleware"
"github.com/rs/cors" "github.com/rs/cors"
"github.com/rs/xid" "github.com/rs/xid"
"golang.org/x/net/webdav" "golang.org/x/net/webdav"
@ -37,9 +38,10 @@ type webDavServer struct {
} }
func (s *webDavServer) listenAndServe() error { func (s *webDavServer) listenAndServe() error {
compressor := middleware.NewCompressor(5, "text/*")
handler := compressor.Handler(s)
httpServer := &http.Server{ httpServer := &http.Server{
Addr: s.binding.GetAddress(), Addr: s.binding.GetAddress(),
Handler: s,
ReadHeaderTimeout: 30 * time.Second, ReadHeaderTimeout: 30 * time.Second,
IdleTimeout: 120 * time.Second, IdleTimeout: 120 * time.Second,
MaxHeaderBytes: 1 << 16, // 64KB MaxHeaderBytes: 1 << 16, // 64KB
@ -55,8 +57,9 @@ func (s *webDavServer) listenAndServe() error {
AllowCredentials: s.config.Cors.AllowCredentials, AllowCredentials: s.config.Cors.AllowCredentials,
OptionsPassthrough: true, OptionsPassthrough: true,
}) })
httpServer.Handler = c.Handler(s) handler = c.Handler(handler)
} }
httpServer.Handler = handler
if certMgr != nil && s.binding.EnableHTTPS { if certMgr != nil && s.binding.EnableHTTPS {
serviceStatus.Bindings = append(serviceStatus.Bindings, s.binding) serviceStatus.Bindings = append(serviceStatus.Bindings, s.binding)
httpServer.TLSConfig = &tls.Config{ httpServer.TLSConfig = &tls.Config{