mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-07 14:50:55 +03:00
WebDAV: add CORS support
This commit is contained in:
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user