mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 22:22:21 +08:00
lib/http: add UsingAuth method
This commit is contained in:
parent
3167292c2f
commit
a9ce86f9a3
|
@ -144,6 +144,7 @@ type Server struct {
|
||||||
cfg Config
|
cfg Config
|
||||||
template *TemplateConfig
|
template *TemplateConfig
|
||||||
htmlTemplate *template.Template
|
htmlTemplate *template.Template
|
||||||
|
usingAuth bool // set if we are using auth middleware
|
||||||
}
|
}
|
||||||
|
|
||||||
// Option allows customizing the server
|
// Option allows customizing the server
|
||||||
|
@ -272,19 +273,23 @@ func NewServer(ctx context.Context, options ...Option) (*Server, error) {
|
||||||
|
|
||||||
func (s *Server) initAuth() {
|
func (s *Server) initAuth() {
|
||||||
if s.auth.CustomAuthFn != nil {
|
if s.auth.CustomAuthFn != nil {
|
||||||
|
s.usingAuth = true
|
||||||
s.mux.Use(MiddlewareAuthCustom(s.auth.CustomAuthFn, s.auth.Realm))
|
s.mux.Use(MiddlewareAuthCustom(s.auth.CustomAuthFn, s.auth.Realm))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.auth.HtPasswd != "" {
|
if s.auth.HtPasswd != "" {
|
||||||
|
s.usingAuth = true
|
||||||
s.mux.Use(MiddlewareAuthHtpasswd(s.auth.HtPasswd, s.auth.Realm))
|
s.mux.Use(MiddlewareAuthHtpasswd(s.auth.HtPasswd, s.auth.Realm))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.auth.BasicUser != "" {
|
if s.auth.BasicUser != "" {
|
||||||
|
s.usingAuth = true
|
||||||
s.mux.Use(MiddlewareAuthBasic(s.auth.BasicUser, s.auth.BasicPass, s.auth.Realm, s.auth.Salt))
|
s.mux.Use(MiddlewareAuthBasic(s.auth.BasicUser, s.auth.BasicPass, s.auth.Realm, s.auth.Salt))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
s.usingAuth = false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) initTemplate() error {
|
func (s *Server) initTemplate() error {
|
||||||
|
@ -426,3 +431,8 @@ func (s *Server) URLs() []string {
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UsingAuth returns true if authentication is required
|
||||||
|
func (s *Server) UsingAuth() bool {
|
||||||
|
return s.usingAuth
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user