WebDAV: add CORS support

This commit is contained in:
Nicola Murino
2020-08-15 15:55:20 +02:00
parent 196a56726e
commit 0dbf0cc81f
10 changed files with 86 additions and 27 deletions

View File

@@ -11,6 +11,7 @@ import (
"strings"
"time"
"github.com/rs/cors"
"github.com/rs/xid"
"golang.org/x/net/webdav"
@@ -58,6 +59,20 @@ func (s *webDavServer) listenAndServe() error {
IdleTimeout: 120 * time.Second,
MaxHeaderBytes: 1 << 16, // 64KB
}
if s.config.Cors.Enabled {
c := cors.New(cors.Options{
AllowedOrigins: s.config.Cors.AllowedOrigins,
AllowedMethods: s.config.Cors.AllowedMethods,
AllowedHeaders: s.config.Cors.AllowedHeaders,
ExposedHeaders: s.config.Cors.ExposedHeaders,
MaxAge: s.config.Cors.MaxAge,
AllowCredentials: s.config.Cors.AllowCredentials,
OptionsPassthrough: true,
})
httpServer.Handler = c.Handler(server)
} else {
httpServer.Handler = server
}
if s.certMgr != nil {
httpServer.TLSConfig = &tls.Config{
GetCertificate: s.certMgr.GetCertificateFunc(),