2021-04-18 19:41:13 +00:00
|
|
|
// Copyright (c) 2015-2021 MinIO, Inc.
|
|
|
|
//
|
|
|
|
// This file is part of MinIO Object Storage stack
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2016-03-27 19:37:21 +00:00
|
|
|
|
2016-08-18 23:23:42 +00:00
|
|
|
package cmd
|
2016-03-27 19:37:21 +00:00
|
|
|
|
2018-03-28 21:14:06 +00:00
|
|
|
import (
|
2021-07-12 17:49:50 +00:00
|
|
|
"compress/gzip"
|
2020-09-09 16:57:37 +00:00
|
|
|
"net"
|
2018-03-28 21:14:06 +00:00
|
|
|
"net/http"
|
|
|
|
|
2021-07-12 17:49:50 +00:00
|
|
|
"github.com/klauspost/compress/gzhttp"
|
2021-11-19 01:19:58 +00:00
|
|
|
"github.com/minio/console/restapi"
|
2021-06-01 21:59:40 +00:00
|
|
|
xhttp "github.com/minio/minio/internal/http"
|
2021-08-09 19:45:59 +00:00
|
|
|
"github.com/minio/minio/internal/logger"
|
2023-01-23 11:12:47 +00:00
|
|
|
"github.com/minio/mux"
|
2021-05-28 22:17:01 +00:00
|
|
|
"github.com/minio/pkg/wildcard"
|
2020-07-07 03:55:19 +00:00
|
|
|
"github.com/rs/cors"
|
2018-03-28 21:14:06 +00:00
|
|
|
)
|
2016-03-27 19:37:21 +00:00
|
|
|
|
2019-12-02 23:54:26 +00:00
|
|
|
func newHTTPServerFn() *xhttp.Server {
|
2021-01-03 19:27:57 +00:00
|
|
|
globalObjLayerMutex.RLock()
|
|
|
|
defer globalObjLayerMutex.RUnlock()
|
2019-12-02 23:54:26 +00:00
|
|
|
return globalHTTPServer
|
|
|
|
}
|
|
|
|
|
2021-01-03 19:27:57 +00:00
|
|
|
func setHTTPServer(h *xhttp.Server) {
|
2019-11-09 17:27:23 +00:00
|
|
|
globalObjLayerMutex.Lock()
|
2021-01-03 19:27:57 +00:00
|
|
|
globalHTTPServer = h
|
|
|
|
globalObjLayerMutex.Unlock()
|
|
|
|
}
|
|
|
|
|
2021-11-19 01:19:58 +00:00
|
|
|
func newConsoleServerFn() *restapi.Server {
|
|
|
|
globalObjLayerMutex.RLock()
|
|
|
|
defer globalObjLayerMutex.RUnlock()
|
|
|
|
return globalConsoleSrv
|
|
|
|
}
|
|
|
|
|
|
|
|
func setConsoleSrv(srv *restapi.Server) {
|
|
|
|
globalObjLayerMutex.Lock()
|
|
|
|
globalConsoleSrv = srv
|
|
|
|
globalObjLayerMutex.Unlock()
|
|
|
|
}
|
|
|
|
|
2021-01-03 19:27:57 +00:00
|
|
|
func newObjectLayerFn() ObjectLayer {
|
|
|
|
globalObjLayerMutex.RLock()
|
|
|
|
defer globalObjLayerMutex.RUnlock()
|
2019-11-09 17:27:23 +00:00
|
|
|
return globalObjectAPI
|
|
|
|
}
|
|
|
|
|
|
|
|
func newCachedObjectLayerFn() CacheObjectLayer {
|
2021-01-03 19:27:57 +00:00
|
|
|
globalObjLayerMutex.RLock()
|
|
|
|
defer globalObjLayerMutex.RUnlock()
|
2019-11-09 17:27:23 +00:00
|
|
|
return globalCacheObjectAPI
|
|
|
|
}
|
|
|
|
|
2021-01-03 19:27:57 +00:00
|
|
|
func setCacheObjectLayer(c CacheObjectLayer) {
|
|
|
|
globalObjLayerMutex.Lock()
|
|
|
|
globalCacheObjectAPI = c
|
|
|
|
globalObjLayerMutex.Unlock()
|
|
|
|
}
|
|
|
|
|
2020-10-28 16:18:35 +00:00
|
|
|
func setObjectLayer(o ObjectLayer) {
|
|
|
|
globalObjLayerMutex.Lock()
|
|
|
|
globalObjectAPI = o
|
|
|
|
globalObjLayerMutex.Unlock()
|
|
|
|
}
|
|
|
|
|
2016-04-12 19:45:15 +00:00
|
|
|
// objectAPIHandler implements and provides http handlers for S3 API.
|
|
|
|
type objectAPIHandlers struct {
|
2016-07-31 21:11:14 +00:00
|
|
|
ObjectAPI func() ObjectLayer
|
2018-03-28 21:14:06 +00:00
|
|
|
CacheAPI func() CacheObjectLayer
|
2016-03-27 19:37:21 +00:00
|
|
|
}
|
|
|
|
|
2020-09-09 16:57:37 +00:00
|
|
|
// getHost tries its best to return the request host.
|
|
|
|
// According to section 14.23 of RFC 2616 the Host header
|
|
|
|
// can include the port number if the default value of 80 is not used.
|
|
|
|
func getHost(r *http.Request) string {
|
|
|
|
if r.URL.IsAbs() {
|
|
|
|
return r.URL.Host
|
|
|
|
}
|
|
|
|
return r.Host
|
|
|
|
}
|
|
|
|
|
2021-03-31 06:19:36 +00:00
|
|
|
func notImplementedHandler(w http.ResponseWriter, r *http.Request) {
|
2021-06-18 03:27:04 +00:00
|
|
|
writeErrorResponse(r.Context(), w, errorCodes.ToAPIErr(ErrNotImplemented), r.URL)
|
2021-03-31 06:19:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type rejectedAPI struct {
|
|
|
|
api string
|
|
|
|
methods []string
|
|
|
|
queries []string
|
|
|
|
path string
|
|
|
|
}
|
|
|
|
|
2021-05-19 16:21:34 +00:00
|
|
|
var rejectedObjAPIs = []rejectedAPI{
|
|
|
|
{
|
|
|
|
api: "torrent",
|
|
|
|
methods: []string{http.MethodPut, http.MethodDelete, http.MethodGet},
|
|
|
|
queries: []string{"torrent", ""},
|
|
|
|
path: "/{object:.+}",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
api: "acl",
|
|
|
|
methods: []string{http.MethodDelete},
|
|
|
|
queries: []string{"acl", ""},
|
|
|
|
path: "/{object:.+}",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var rejectedBucketAPIs = []rejectedAPI{
|
2021-03-31 06:19:36 +00:00
|
|
|
{
|
|
|
|
api: "inventory",
|
|
|
|
methods: []string{http.MethodGet, http.MethodPut, http.MethodDelete},
|
|
|
|
queries: []string{"inventory", ""},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
api: "cors",
|
|
|
|
methods: []string{http.MethodPut, http.MethodDelete},
|
|
|
|
queries: []string{"cors", ""},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
api: "metrics",
|
|
|
|
methods: []string{http.MethodGet, http.MethodPut, http.MethodDelete},
|
|
|
|
queries: []string{"metrics", ""},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
api: "website",
|
|
|
|
methods: []string{http.MethodPut},
|
|
|
|
queries: []string{"website", ""},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
api: "logging",
|
|
|
|
methods: []string{http.MethodPut, http.MethodDelete},
|
|
|
|
queries: []string{"logging", ""},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
api: "accelerate",
|
|
|
|
methods: []string{http.MethodPut, http.MethodDelete},
|
|
|
|
queries: []string{"accelerate", ""},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
api: "requestPayment",
|
|
|
|
methods: []string{http.MethodPut, http.MethodDelete},
|
|
|
|
queries: []string{"requestPayment", ""},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
api: "acl",
|
|
|
|
methods: []string{http.MethodDelete, http.MethodPut, http.MethodHead},
|
|
|
|
queries: []string{"acl", ""},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
api: "publicAccessBlock",
|
|
|
|
methods: []string{http.MethodDelete, http.MethodPut, http.MethodGet},
|
|
|
|
queries: []string{"publicAccessBlock", ""},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
api: "ownershipControls",
|
|
|
|
methods: []string{http.MethodDelete, http.MethodPut, http.MethodGet},
|
|
|
|
queries: []string{"ownershipControls", ""},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
api: "intelligent-tiering",
|
|
|
|
methods: []string{http.MethodDelete, http.MethodPut, http.MethodGet},
|
|
|
|
queries: []string{"intelligent-tiering", ""},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
api: "analytics",
|
|
|
|
methods: []string{http.MethodDelete, http.MethodPut, http.MethodGet},
|
|
|
|
queries: []string{"analytics", ""},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2016-03-27 19:37:21 +00:00
|
|
|
// registerAPIRouter - registers S3 compatible APIs.
|
2020-09-15 20:57:15 +00:00
|
|
|
func registerAPIRouter(router *mux.Router) {
|
2016-10-05 19:48:07 +00:00
|
|
|
// Initialize API.
|
|
|
|
api := objectAPIHandlers{
|
2019-11-09 17:27:23 +00:00
|
|
|
ObjectAPI: newObjectLayerFn,
|
|
|
|
CacheAPI: newCachedObjectLayerFn,
|
2016-10-05 19:48:07 +00:00
|
|
|
}
|
|
|
|
|
2016-03-27 19:37:21 +00:00
|
|
|
// API Router
|
2019-08-06 19:08:58 +00:00
|
|
|
apiRouter := router.PathPrefix(SlashSeparator).Subrouter()
|
2020-09-09 16:57:37 +00:00
|
|
|
|
2018-04-22 02:23:54 +00:00
|
|
|
var routers []*mux.Router
|
2019-02-23 03:18:01 +00:00
|
|
|
for _, domainName := range globalDomainNames {
|
2020-09-09 16:57:37 +00:00
|
|
|
if IsKubernetes() {
|
|
|
|
routers = append(routers, apiRouter.MatcherFunc(func(r *http.Request, match *mux.RouteMatch) bool {
|
2020-09-23 19:10:09 +00:00
|
|
|
host, _, err := net.SplitHostPort(getHost(r))
|
|
|
|
if err != nil {
|
|
|
|
host = r.Host
|
|
|
|
}
|
2020-09-09 16:57:37 +00:00
|
|
|
// Make sure to skip matching minio.<domain>` this is
|
|
|
|
// specifically meant for operator/k8s deployment
|
|
|
|
// The reason we need to skip this is for a special
|
|
|
|
// usecase where we need to make sure that
|
|
|
|
// minio.<namespace>.svc.<cluster_domain> is ignored
|
|
|
|
// by the bucketDNS style to ensure that path style
|
|
|
|
// is available and honored at this domain.
|
|
|
|
//
|
|
|
|
// All other `<bucket>.<namespace>.svc.<cluster_domain>`
|
|
|
|
// makes sure that buckets are routed through this matcher
|
|
|
|
// to match for `<bucket>`
|
|
|
|
return host != minioReservedBucket+"."+domainName
|
|
|
|
}).Host("{bucket:.+}."+domainName).Subrouter())
|
|
|
|
} else {
|
|
|
|
routers = append(routers, apiRouter.Host("{bucket:.+}."+domainName).Subrouter())
|
|
|
|
}
|
2017-11-15 00:56:24 +00:00
|
|
|
}
|
|
|
|
routers = append(routers, apiRouter.PathPrefix("/{bucket}").Subrouter())
|
2016-03-27 19:37:21 +00:00
|
|
|
|
2021-08-09 19:45:59 +00:00
|
|
|
gz, err := gzhttp.NewWrapper(gzhttp.MinSize(1000), gzhttp.CompressionLevel(gzip.BestSpeed))
|
|
|
|
if err != nil {
|
|
|
|
// Static params, so this is very unlikely.
|
|
|
|
logger.Fatal(err, "Unable to initialize server")
|
2021-07-12 17:49:50 +00:00
|
|
|
}
|
|
|
|
|
2021-03-31 06:19:36 +00:00
|
|
|
for _, router := range routers {
|
2021-05-19 16:21:34 +00:00
|
|
|
// Register all rejected object APIs
|
|
|
|
for _, r := range rejectedObjAPIs {
|
|
|
|
t := router.Methods(r.methods...).
|
|
|
|
HandlerFunc(collectAPIStats(r.api, httpTraceAll(notImplementedHandler))).
|
|
|
|
Queries(r.queries...)
|
|
|
|
t.Path(r.path)
|
|
|
|
}
|
|
|
|
|
2017-11-15 00:56:24 +00:00
|
|
|
// Object operations
|
|
|
|
// HeadObject
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodHead).Path("/{object:.+}").HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("headobject", maxClients(gz(httpTraceAll(api.HeadObjectHandler)))))
|
2017-11-15 00:56:24 +00:00
|
|
|
// CopyObjectPart
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodPut).Path("/{object:.+}").
|
2020-09-09 16:57:37 +00:00
|
|
|
HeadersRegexp(xhttp.AmzCopySource, ".*?(\\/|%2F).*?").
|
2021-07-12 17:49:50 +00:00
|
|
|
HandlerFunc(collectAPIStats("copyobjectpart", maxClients(gz(httpTraceAll(api.CopyObjectPartHandler))))).
|
2020-09-09 16:57:37 +00:00
|
|
|
Queries("partNumber", "{partNumber:[0-9]+}", "uploadId", "{uploadId:.*}")
|
2017-11-15 00:56:24 +00:00
|
|
|
// PutObjectPart
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodPut).Path("/{object:.+}").HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("putobjectpart", maxClients(gz(httpTraceHdrs(api.PutObjectPartHandler))))).Queries("partNumber", "{partNumber:[0-9]+}", "uploadId", "{uploadId:.*}")
|
2019-08-19 21:02:54 +00:00
|
|
|
// ListObjectParts
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodGet).Path("/{object:.+}").HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("listobjectparts", maxClients(gz(httpTraceAll(api.ListObjectPartsHandler))))).Queries("uploadId", "{uploadId:.*}")
|
2017-11-15 00:56:24 +00:00
|
|
|
// CompleteMultipartUpload
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodPost).Path("/{object:.+}").HandlerFunc(
|
2021-08-24 14:14:34 +00:00
|
|
|
collectAPIStats("completemultipartupload", maxClients(gz(httpTraceAll(api.CompleteMultipartUploadHandler))))).Queries("uploadId", "{uploadId:.*}")
|
2017-11-15 00:56:24 +00:00
|
|
|
// NewMultipartUpload
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodPost).Path("/{object:.+}").HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("newmultipartupload", maxClients(gz(httpTraceAll(api.NewMultipartUploadHandler))))).Queries("uploads", "")
|
2017-11-15 00:56:24 +00:00
|
|
|
// AbortMultipartUpload
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodDelete).Path("/{object:.+}").HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("abortmultipartupload", maxClients(gz(httpTraceAll(api.AbortMultipartUploadHandler))))).Queries("uploadId", "{uploadId:.*}")
|
2018-06-01 02:43:50 +00:00
|
|
|
// GetObjectACL - this is a dummy call.
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodGet).Path("/{object:.+}").HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("getobjectacl", maxClients(gz(httpTraceHdrs(api.GetObjectACLHandler))))).Queries("acl", "")
|
2020-02-16 06:07:52 +00:00
|
|
|
// PutObjectACL - this is a dummy call.
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodPut).Path("/{object:.+}").HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("putobjectacl", maxClients(gz(httpTraceHdrs(api.PutObjectACLHandler))))).Queries("acl", "")
|
2020-01-20 16:45:59 +00:00
|
|
|
// GetObjectTagging
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodGet).Path("/{object:.+}").HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("getobjecttagging", maxClients(gz(httpTraceHdrs(api.GetObjectTaggingHandler))))).Queries("tagging", "")
|
2020-01-20 16:45:59 +00:00
|
|
|
// PutObjectTagging
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodPut).Path("/{object:.+}").HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("putobjecttagging", maxClients(gz(httpTraceHdrs(api.PutObjectTaggingHandler))))).Queries("tagging", "")
|
2020-01-20 16:45:59 +00:00
|
|
|
// DeleteObjectTagging
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodDelete).Path("/{object:.+}").HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("deleteobjecttagging", maxClients(gz(httpTraceHdrs(api.DeleteObjectTaggingHandler))))).Queries("tagging", "")
|
2018-08-15 10:30:19 +00:00
|
|
|
// SelectObjectContent
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodPost).Path("/{object:.+}").HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("selectobjectcontent", maxClients(gz(httpTraceHdrs(api.SelectObjectContentHandler))))).Queries("select", "").Queries("select-type", "2")
|
2019-11-20 21:18:09 +00:00
|
|
|
// GetObjectRetention
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodGet).Path("/{object:.+}").HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("getobjectretention", maxClients(gz(httpTraceAll(api.GetObjectRetentionHandler))))).Queries("retention", "")
|
2020-01-16 23:41:56 +00:00
|
|
|
// GetObjectLegalHold
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodGet).Path("/{object:.+}").HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("getobjectlegalhold", maxClients(gz(httpTraceAll(api.GetObjectLegalHoldHandler))))).Queries("legal-hold", "")
|
2023-03-07 16:12:41 +00:00
|
|
|
// GetObject with lambda ARNs
|
|
|
|
router.Methods(http.MethodGet).Path("/{object:.+}").HandlerFunc(
|
|
|
|
collectAPIStats("getobject", maxClients(gz(httpTraceHdrs(api.GetObjectLambdaHandler))))).Queries("lambdaArn", "{lambdaArn:.*}")
|
|
|
|
// GetObject
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodGet).Path("/{object:.+}").HandlerFunc(
|
2022-02-14 17:19:01 +00:00
|
|
|
collectAPIStats("getobject", maxClients(gz(httpTraceHdrs(api.GetObjectHandler)))))
|
2017-11-15 00:56:24 +00:00
|
|
|
// CopyObject
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodPut).Path("/{object:.+}").HeadersRegexp(xhttp.AmzCopySource, ".*?(\\/|%2F).*?").HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("copyobject", maxClients(gz(httpTraceAll(api.CopyObjectHandler)))))
|
2019-11-20 21:18:09 +00:00
|
|
|
// PutObjectRetention
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodPut).Path("/{object:.+}").HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("putobjectretention", maxClients(gz(httpTraceAll(api.PutObjectRetentionHandler))))).Queries("retention", "")
|
2020-01-16 23:41:56 +00:00
|
|
|
// PutObjectLegalHold
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodPut).Path("/{object:.+}").HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("putobjectlegalhold", maxClients(gz(httpTraceAll(api.PutObjectLegalHoldHandler))))).Queries("legal-hold", "")
|
2020-01-16 23:41:56 +00:00
|
|
|
|
2021-03-27 00:15:09 +00:00
|
|
|
// PutObject with auto-extract support for zip
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodPut).Path("/{object:.+}").HeadersRegexp(xhttp.AmzSnowballExtract, "true").HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("putobject", maxClients(gz(httpTraceHdrs(api.PutObjectExtractHandler)))))
|
2021-03-27 00:15:09 +00:00
|
|
|
|
2017-11-15 00:56:24 +00:00
|
|
|
// PutObject
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodPut).Path("/{object:.+}").HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("putobject", maxClients(gz(httpTraceHdrs(api.PutObjectHandler)))))
|
2021-03-27 00:15:09 +00:00
|
|
|
|
2017-11-15 00:56:24 +00:00
|
|
|
// DeleteObject
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodDelete).Path("/{object:.+}").HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("deleteobject", maxClients(gz(httpTraceAll(api.DeleteObjectHandler)))))
|
2016-03-27 19:37:21 +00:00
|
|
|
|
2021-03-02 07:10:33 +00:00
|
|
|
// PostRestoreObject
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodPost).Path("/{object:.+}").HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("restoreobject", maxClients(gz(httpTraceAll(api.PostRestoreObjectHandler))))).Queries("restore", "")
|
2021-03-02 07:10:33 +00:00
|
|
|
|
2021-11-16 17:28:29 +00:00
|
|
|
// Bucket operations
|
|
|
|
|
2017-11-15 00:56:24 +00:00
|
|
|
// GetBucketLocation
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodGet).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("getbucketlocation", maxClients(gz(httpTraceAll(api.GetBucketLocationHandler))))).Queries("location", "")
|
2017-11-15 00:56:24 +00:00
|
|
|
// GetBucketPolicy
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodGet).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("getbucketpolicy", maxClients(gz(httpTraceAll(api.GetBucketPolicyHandler))))).Queries("policy", "")
|
2019-07-19 20:20:33 +00:00
|
|
|
// GetBucketLifecycle
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodGet).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("getbucketlifecycle", maxClients(gz(httpTraceAll(api.GetBucketLifecycleHandler))))).Queries("lifecycle", "")
|
2020-02-05 09:42:34 +00:00
|
|
|
// GetBucketEncryption
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodGet).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("getbucketencryption", maxClients(gz(httpTraceAll(api.GetBucketEncryptionHandler))))).Queries("encryption", "")
|
2020-07-22 00:49:56 +00:00
|
|
|
// GetBucketObjectLockConfig
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodGet).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("getbucketobjectlockconfiguration", maxClients(gz(httpTraceAll(api.GetBucketObjectLockConfigHandler))))).Queries("object-lock", "")
|
2020-07-22 00:49:56 +00:00
|
|
|
// GetBucketReplicationConfig
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodGet).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("getbucketreplicationconfiguration", maxClients(gz(httpTraceAll(api.GetBucketReplicationConfigHandler))))).Queries("replication", "")
|
2020-07-22 00:49:56 +00:00
|
|
|
// GetBucketVersioning
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodGet).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("getbucketversioning", maxClients(gz(httpTraceAll(api.GetBucketVersioningHandler))))).Queries("versioning", "")
|
2020-07-22 00:49:56 +00:00
|
|
|
// GetBucketNotification
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodGet).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("getbucketnotification", maxClients(gz(httpTraceAll(api.GetBucketNotificationHandler))))).Queries("notification", "")
|
2020-07-22 00:49:56 +00:00
|
|
|
// ListenNotification
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodGet).HandlerFunc(
|
2022-06-05 21:29:12 +00:00
|
|
|
collectAPIStats("listennotification", gz(httpTraceAll(api.ListenNotificationHandler)))).Queries("events", "{events:.*}")
|
2022-02-10 18:16:52 +00:00
|
|
|
// ResetBucketReplicationStatus - MinIO extension API
|
|
|
|
router.Methods(http.MethodGet).HandlerFunc(
|
|
|
|
collectAPIStats("resetbucketreplicationstatus", maxClients(gz(httpTraceAll(api.ResetBucketReplicationStatusHandler))))).Queries("replication-reset-status", "")
|
2018-05-10 04:02:26 +00:00
|
|
|
|
2019-02-09 00:18:13 +00:00
|
|
|
// Dummy Bucket Calls
|
2018-05-10 04:02:26 +00:00
|
|
|
// GetBucketACL -- this is a dummy call.
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodGet).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("getbucketacl", maxClients(gz(httpTraceAll(api.GetBucketACLHandler))))).Queries("acl", "")
|
2020-02-16 06:07:52 +00:00
|
|
|
// PutBucketACL -- this is a dummy call.
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodPut).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("putbucketacl", maxClients(gz(httpTraceAll(api.PutBucketACLHandler))))).Queries("acl", "")
|
2019-02-09 00:18:13 +00:00
|
|
|
// GetBucketCors - this is a dummy call.
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodGet).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("getbucketcors", maxClients(gz(httpTraceAll(api.GetBucketCorsHandler))))).Queries("cors", "")
|
2019-02-09 00:18:13 +00:00
|
|
|
// GetBucketWebsiteHandler - this is a dummy call.
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodGet).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("getbucketwebsite", maxClients(gz(httpTraceAll(api.GetBucketWebsiteHandler))))).Queries("website", "")
|
2019-02-09 00:18:13 +00:00
|
|
|
// GetBucketAccelerateHandler - this is a dummy call.
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodGet).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("getbucketaccelerate", maxClients(gz(httpTraceAll(api.GetBucketAccelerateHandler))))).Queries("accelerate", "")
|
2019-02-09 00:18:13 +00:00
|
|
|
// GetBucketRequestPaymentHandler - this is a dummy call.
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodGet).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("getbucketrequestpayment", maxClients(gz(httpTraceAll(api.GetBucketRequestPaymentHandler))))).Queries("requestPayment", "")
|
2019-02-09 00:18:13 +00:00
|
|
|
// GetBucketLoggingHandler - this is a dummy call.
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodGet).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("getbucketlogging", maxClients(gz(httpTraceAll(api.GetBucketLoggingHandler))))).Queries("logging", "")
|
2020-05-05 21:18:13 +00:00
|
|
|
// GetBucketTaggingHandler
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodGet).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("getbuckettagging", maxClients(gz(httpTraceAll(api.GetBucketTaggingHandler))))).Queries("tagging", "")
|
2021-11-16 17:28:29 +00:00
|
|
|
// DeleteBucketWebsiteHandler
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodDelete).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("deletebucketwebsite", maxClients(gz(httpTraceAll(api.DeleteBucketWebsiteHandler))))).Queries("website", "")
|
2019-02-09 00:18:13 +00:00
|
|
|
// DeleteBucketTaggingHandler
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodDelete).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("deletebuckettagging", maxClients(gz(httpTraceAll(api.DeleteBucketTaggingHandler))))).Queries("tagging", "")
|
2018-05-10 04:02:26 +00:00
|
|
|
|
2017-11-15 00:56:24 +00:00
|
|
|
// ListMultipartUploads
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodGet).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("listmultipartuploads", maxClients(gz(httpTraceAll(api.ListMultipartUploadsHandler))))).Queries("uploads", "")
|
2019-11-21 09:54:49 +00:00
|
|
|
// ListObjectsV2M
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodGet).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("listobjectsv2M", maxClients(gz(httpTraceAll(api.ListObjectsV2MHandler))))).Queries("list-type", "2", "metadata", "true")
|
2017-11-15 00:56:24 +00:00
|
|
|
// ListObjectsV2
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodGet).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("listobjectsv2", maxClients(gz(httpTraceAll(api.ListObjectsV2Handler))))).Queries("list-type", "2")
|
2020-06-13 03:04:01 +00:00
|
|
|
// ListObjectVersions
|
2023-03-30 19:20:42 +00:00
|
|
|
router.Methods(http.MethodGet).HandlerFunc(
|
|
|
|
collectAPIStats("listobjectversions", maxClients(gz(httpTraceAll(api.ListObjectVersionsMHandler))))).Queries("versions", "", "metadata", "true")
|
|
|
|
// ListObjectVersions
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodGet).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("listobjectversions", maxClients(gz(httpTraceAll(api.ListObjectVersionsHandler))))).Queries("versions", "")
|
2021-03-02 07:10:33 +00:00
|
|
|
// GetBucketPolicyStatus
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodGet).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("getpolicystatus", maxClients(gz(httpTraceAll(api.GetBucketPolicyStatusHandler))))).Queries("policyStatus", "")
|
2019-07-19 20:20:33 +00:00
|
|
|
// PutBucketLifecycle
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodPut).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("putbucketlifecycle", maxClients(gz(httpTraceAll(api.PutBucketLifecycleHandler))))).Queries("lifecycle", "")
|
2020-07-22 00:49:56 +00:00
|
|
|
// PutBucketReplicationConfig
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodPut).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("putbucketreplicationconfiguration", maxClients(gz(httpTraceAll(api.PutBucketReplicationConfigHandler))))).Queries("replication", "")
|
2020-02-05 09:42:34 +00:00
|
|
|
// PutBucketEncryption
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodPut).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("putbucketencryption", maxClients(gz(httpTraceAll(api.PutBucketEncryptionHandler))))).Queries("encryption", "")
|
2020-02-05 09:42:34 +00:00
|
|
|
|
2017-11-15 00:56:24 +00:00
|
|
|
// PutBucketPolicy
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodPut).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("putbucketpolicy", maxClients(gz(httpTraceAll(api.PutBucketPolicyHandler))))).Queries("policy", "")
|
2019-07-19 20:20:33 +00:00
|
|
|
|
2019-11-12 22:50:18 +00:00
|
|
|
// PutBucketObjectLockConfig
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodPut).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("putbucketobjectlockconfig", maxClients(gz(httpTraceAll(api.PutBucketObjectLockConfigHandler))))).Queries("object-lock", "")
|
2020-05-05 21:18:13 +00:00
|
|
|
// PutBucketTaggingHandler
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodPut).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("putbuckettagging", maxClients(gz(httpTraceAll(api.PutBucketTaggingHandler))))).Queries("tagging", "")
|
2019-11-12 22:50:18 +00:00
|
|
|
// PutBucketVersioning
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodPut).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("putbucketversioning", maxClients(gz(httpTraceAll(api.PutBucketVersioningHandler))))).Queries("versioning", "")
|
2017-11-15 00:56:24 +00:00
|
|
|
// PutBucketNotification
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodPut).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("putbucketnotification", maxClients(gz(httpTraceAll(api.PutBucketNotificationHandler))))).Queries("notification", "")
|
2022-02-10 18:16:52 +00:00
|
|
|
// ResetBucketReplicationStart - MinIO extension API
|
2021-06-02 02:59:11 +00:00
|
|
|
router.Methods(http.MethodPut).HandlerFunc(
|
2022-02-10 18:16:52 +00:00
|
|
|
collectAPIStats("resetbucketreplicationstart", maxClients(gz(httpTraceAll(api.ResetBucketReplicationStartHandler))))).Queries("replication-reset", "")
|
|
|
|
|
2017-11-15 00:56:24 +00:00
|
|
|
// PutBucket
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodPut).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("putbucket", maxClients(gz(httpTraceAll(api.PutBucketHandler)))))
|
2017-11-15 00:56:24 +00:00
|
|
|
// HeadBucket
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodHead).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("headbucket", maxClients(gz(httpTraceAll(api.HeadBucketHandler)))))
|
2017-11-15 00:56:24 +00:00
|
|
|
// PostPolicy
|
2023-03-20 04:15:20 +00:00
|
|
|
router.Methods(http.MethodPost).MatcherFunc(func(r *http.Request, _ *mux.RouteMatch) bool {
|
|
|
|
return isRequestPostPolicySignatureV4(r)
|
|
|
|
}).HandlerFunc(collectAPIStats("postpolicybucket", maxClients(gz(httpTraceHdrs(api.PostPolicyBucketHandler)))))
|
2017-11-15 00:56:24 +00:00
|
|
|
// DeleteMultipleObjects
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodPost).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("deletemultipleobjects", maxClients(gz(httpTraceAll(api.DeleteMultipleObjectsHandler))))).Queries("delete", "")
|
2017-11-15 00:56:24 +00:00
|
|
|
// DeleteBucketPolicy
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodDelete).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("deletebucketpolicy", maxClients(gz(httpTraceAll(api.DeleteBucketPolicyHandler))))).Queries("policy", "")
|
2020-07-22 00:49:56 +00:00
|
|
|
// DeleteBucketReplication
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodDelete).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("deletebucketreplicationconfiguration", maxClients(gz(httpTraceAll(api.DeleteBucketReplicationConfigHandler))))).Queries("replication", "")
|
2019-07-19 20:20:33 +00:00
|
|
|
// DeleteBucketLifecycle
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodDelete).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("deletebucketlifecycle", maxClients(gz(httpTraceAll(api.DeleteBucketLifecycleHandler))))).Queries("lifecycle", "")
|
2020-02-05 09:42:34 +00:00
|
|
|
// DeleteBucketEncryption
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodDelete).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("deletebucketencryption", maxClients(gz(httpTraceAll(api.DeleteBucketEncryptionHandler))))).Queries("encryption", "")
|
2017-11-15 00:56:24 +00:00
|
|
|
// DeleteBucket
|
2021-03-31 06:19:36 +00:00
|
|
|
router.Methods(http.MethodDelete).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("deletebucket", maxClients(gz(httpTraceAll(api.DeleteBucketHandler)))))
|
2021-05-19 16:21:34 +00:00
|
|
|
|
2021-04-03 16:03:42 +00:00
|
|
|
// MinIO extension API for replication.
|
|
|
|
//
|
|
|
|
// GetBucketReplicationMetrics
|
|
|
|
router.Methods(http.MethodGet).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("getbucketreplicationmetrics", maxClients(gz(httpTraceAll(api.GetBucketReplicationMetricsHandler))))).Queries("replication-metrics", "")
|
2021-04-05 20:36:39 +00:00
|
|
|
|
2021-05-19 16:21:34 +00:00
|
|
|
// Register rejected bucket APIs
|
|
|
|
for _, r := range rejectedBucketAPIs {
|
|
|
|
router.Methods(r.methods...).
|
|
|
|
HandlerFunc(collectAPIStats(r.api, httpTraceAll(notImplementedHandler))).
|
|
|
|
Queries(r.queries...)
|
|
|
|
}
|
|
|
|
|
2021-04-05 20:36:39 +00:00
|
|
|
// S3 ListObjectsV1 (Legacy)
|
|
|
|
router.Methods(http.MethodGet).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("listobjectsv1", maxClients(gz(httpTraceAll(api.ListObjectsV1Handler)))))
|
2017-11-15 00:56:24 +00:00
|
|
|
}
|
2016-03-27 19:37:21 +00:00
|
|
|
|
2021-11-16 17:28:29 +00:00
|
|
|
// Root operation
|
2016-03-27 19:37:21 +00:00
|
|
|
|
2020-07-20 19:52:49 +00:00
|
|
|
// ListenNotification
|
|
|
|
apiRouter.Methods(http.MethodGet).Path(SlashSeparator).HandlerFunc(
|
2022-06-05 21:29:12 +00:00
|
|
|
collectAPIStats("listennotification", gz(httpTraceAll(api.ListenNotificationHandler)))).Queries("events", "{events:.*}")
|
2020-07-20 19:52:49 +00:00
|
|
|
|
2016-03-27 19:37:21 +00:00
|
|
|
// ListBuckets
|
2020-03-24 19:43:40 +00:00
|
|
|
apiRouter.Methods(http.MethodGet).Path(SlashSeparator).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("listbuckets", maxClients(gz(httpTraceAll(api.ListBucketsHandler)))))
|
2017-11-15 00:56:24 +00:00
|
|
|
|
2020-05-22 01:51:23 +00:00
|
|
|
// S3 browser with signature v4 adds '//' for ListBuckets request, so rather
|
|
|
|
// than failing with UnknownAPIRequest we simply handle it for now.
|
|
|
|
apiRouter.Methods(http.MethodGet).Path(SlashSeparator + SlashSeparator).HandlerFunc(
|
2021-07-12 17:49:50 +00:00
|
|
|
collectAPIStats("listbuckets", maxClients(gz(httpTraceAll(api.ListBucketsHandler)))))
|
2020-05-22 01:51:23 +00:00
|
|
|
|
2019-11-04 17:30:59 +00:00
|
|
|
// If none of the routes match add default error handler routes
|
2020-09-28 20:33:49 +00:00
|
|
|
apiRouter.NotFoundHandler = collectAPIStats("notfound", httpTraceAll(errorResponseHandler))
|
2020-10-28 16:18:35 +00:00
|
|
|
apiRouter.MethodNotAllowedHandler = collectAPIStats("methodnotallowed", httpTraceAll(methodNotAllowedHandler("S3")))
|
2016-03-27 19:37:21 +00:00
|
|
|
}
|
2020-07-07 03:55:19 +00:00
|
|
|
|
2020-07-12 17:56:57 +00:00
|
|
|
// corsHandler handler for CORS (Cross Origin Resource Sharing)
|
|
|
|
func corsHandler(handler http.Handler) http.Handler {
|
2020-07-07 03:55:19 +00:00
|
|
|
commonS3Headers := []string{
|
|
|
|
xhttp.Date,
|
|
|
|
xhttp.ETag,
|
|
|
|
xhttp.ServerInfo,
|
|
|
|
xhttp.Connection,
|
|
|
|
xhttp.AcceptRanges,
|
|
|
|
xhttp.ContentRange,
|
|
|
|
xhttp.ContentEncoding,
|
|
|
|
xhttp.ContentLength,
|
|
|
|
xhttp.ContentType,
|
2020-07-27 16:03:38 +00:00
|
|
|
xhttp.ContentDisposition,
|
2020-07-24 07:46:51 +00:00
|
|
|
xhttp.LastModified,
|
|
|
|
xhttp.ContentLanguage,
|
|
|
|
xhttp.CacheControl,
|
|
|
|
xhttp.RetryAfter,
|
|
|
|
xhttp.AmzBucketRegion,
|
|
|
|
xhttp.Expires,
|
2020-07-07 03:55:19 +00:00
|
|
|
"X-Amz*",
|
|
|
|
"x-amz*",
|
|
|
|
"*",
|
|
|
|
}
|
|
|
|
|
2020-07-12 17:56:57 +00:00
|
|
|
return cors.New(cors.Options{
|
2020-07-07 03:55:19 +00:00
|
|
|
AllowOriginFunc: func(origin string) bool {
|
2023-02-27 18:10:45 +00:00
|
|
|
allowedOrigins := globalAPIConfig.getCorsAllowOrigins()
|
|
|
|
if len(allowedOrigins) == 0 {
|
|
|
|
allowedOrigins = []string{"*"}
|
|
|
|
}
|
|
|
|
for _, allowedOrigin := range allowedOrigins {
|
2020-07-07 03:55:19 +00:00
|
|
|
if wildcard.MatchSimple(allowedOrigin, origin) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
},
|
|
|
|
AllowedMethods: []string{
|
|
|
|
http.MethodGet,
|
|
|
|
http.MethodPut,
|
|
|
|
http.MethodHead,
|
|
|
|
http.MethodPost,
|
|
|
|
http.MethodDelete,
|
|
|
|
http.MethodOptions,
|
|
|
|
http.MethodPatch,
|
|
|
|
},
|
|
|
|
AllowedHeaders: commonS3Headers,
|
|
|
|
ExposedHeaders: commonS3Headers,
|
|
|
|
AllowCredentials: true,
|
2020-07-12 17:56:57 +00:00
|
|
|
}).Handler(handler)
|
2020-07-07 03:55:19 +00:00
|
|
|
}
|