Fixes over bucket router

should work over {bucket}.{domain} and /{bucket}

Signed-off-by: Evgeniy Kulikov <kim@nspcc.ru>
This commit is contained in:
Evgeniy Kulikov 2020-12-10 18:13:28 +03:00
parent 793925497a
commit ef0e179b33

View file

@ -167,7 +167,7 @@ func GetRequestID(v interface{}) string {
} }
} }
func Attach(r *mux.Router, m MaxClients, h Handler, center auth.Center, log *zap.Logger) { func Attach(r *mux.Router, domains []string, m MaxClients, h Handler, center auth.Center, log *zap.Logger) {
api := r.PathPrefix(SlashSeparator).Subrouter() api := r.PathPrefix(SlashSeparator).Subrouter()
api.Use( api.Use(
@ -181,8 +181,14 @@ func Attach(r *mux.Router, m MaxClients, h Handler, center auth.Center, log *zap
// Attach user authentication for all S3 routes. // Attach user authentication for all S3 routes.
AttachUserAuth(api, center, log) AttachUserAuth(api, center, log)
bucket := api.PathPrefix("/{bucket}").Subrouter() buckets := make([]*mux.Router, 0, len(domains)+1)
buckets = append(buckets, api.PathPrefix("/{bucket}").Subrouter())
for _, domain := range domains {
buckets = append(buckets, api.Host("{bucket:.+}."+domain).Subrouter())
}
for _, bucket := range buckets {
// Object operations // Object operations
// HeadObject // HeadObject
bucket.Methods(http.MethodHead).Path("/{object:.+}").HandlerFunc( bucket.Methods(http.MethodHead).Path("/{object:.+}").HandlerFunc(
@ -432,7 +438,7 @@ func Attach(r *mux.Router, m MaxClients, h Handler, center auth.Center, log *zap
bucket.Methods(http.MethodDelete).HandlerFunc( bucket.Methods(http.MethodDelete).HandlerFunc(
m.Handle(metrics.APIStats("deletebucket", h.DeleteBucketHandler))). m.Handle(metrics.APIStats("deletebucket", h.DeleteBucketHandler))).
Name("DeleteBucket") Name("DeleteBucket")
}
// Root operation // Root operation
// ListBuckets // ListBuckets