| 
									
										
										
										
											2021-04-19 03:41:13 +08: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-28 03:37:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-19 07:23:42 +08:00
										 |  |  | package cmd | 
					
						
							| 
									
										
										
										
											2016-03-28 03:37:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-29 05:14:06 +08:00
										 |  |  | import ( | 
					
						
							| 
									
										
										
										
											2020-09-10 00:57:37 +08:00
										 |  |  | 	"net" | 
					
						
							| 
									
										
										
										
											2018-03-29 05:14:06 +08:00
										 |  |  | 	"net/http" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-28 03:19:13 +08:00
										 |  |  | 	consoleapi "github.com/minio/console/api" | 
					
						
							| 
									
										
										
										
											2021-06-02 05:59:40 +08:00
										 |  |  | 	xhttp "github.com/minio/minio/internal/http" | 
					
						
							| 
									
										
										
										
											2023-01-23 19:12:47 +08:00
										 |  |  | 	"github.com/minio/mux" | 
					
						
							| 
									
										
										
										
											2024-05-25 07:05:23 +08:00
										 |  |  | 	"github.com/minio/pkg/v3/wildcard" | 
					
						
							| 
									
										
										
										
											2020-07-07 11:55:19 +08:00
										 |  |  | 	"github.com/rs/cors" | 
					
						
							| 
									
										
										
										
											2018-03-29 05:14:06 +08:00
										 |  |  | ) | 
					
						
							| 
									
										
										
										
											2016-03-28 03:37:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-03 07:54:26 +08:00
										 |  |  | func newHTTPServerFn() *xhttp.Server { | 
					
						
							| 
									
										
										
										
											2021-01-04 03:27:57 +08:00
										 |  |  | 	globalObjLayerMutex.RLock() | 
					
						
							|  |  |  | 	defer globalObjLayerMutex.RUnlock() | 
					
						
							| 
									
										
										
										
											2019-12-03 07:54:26 +08:00
										 |  |  | 	return globalHTTPServer | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-04 03:27:57 +08:00
										 |  |  | func setHTTPServer(h *xhttp.Server) { | 
					
						
							| 
									
										
										
										
											2019-11-10 01:27:23 +08:00
										 |  |  | 	globalObjLayerMutex.Lock() | 
					
						
							| 
									
										
										
										
											2021-01-04 03:27:57 +08:00
										 |  |  | 	globalHTTPServer = h | 
					
						
							|  |  |  | 	globalObjLayerMutex.Unlock() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-28 03:19:13 +08:00
										 |  |  | func newConsoleServerFn() *consoleapi.Server { | 
					
						
							| 
									
										
										
										
											2021-11-19 09:19:58 +08:00
										 |  |  | 	globalObjLayerMutex.RLock() | 
					
						
							|  |  |  | 	defer globalObjLayerMutex.RUnlock() | 
					
						
							|  |  |  | 	return globalConsoleSrv | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-28 03:19:13 +08:00
										 |  |  | func setConsoleSrv(srv *consoleapi.Server) { | 
					
						
							| 
									
										
										
										
											2021-11-19 09:19:58 +08:00
										 |  |  | 	globalObjLayerMutex.Lock() | 
					
						
							|  |  |  | 	globalConsoleSrv = srv | 
					
						
							|  |  |  | 	globalObjLayerMutex.Unlock() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-04 03:27:57 +08:00
										 |  |  | func newObjectLayerFn() ObjectLayer { | 
					
						
							|  |  |  | 	globalObjLayerMutex.RLock() | 
					
						
							|  |  |  | 	defer globalObjLayerMutex.RUnlock() | 
					
						
							| 
									
										
										
										
											2019-11-10 01:27:23 +08:00
										 |  |  | 	return globalObjectAPI | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-29 00:18:35 +08:00
										 |  |  | func setObjectLayer(o ObjectLayer) { | 
					
						
							|  |  |  | 	globalObjLayerMutex.Lock() | 
					
						
							|  |  |  | 	globalObjectAPI = o | 
					
						
							|  |  |  | 	globalObjLayerMutex.Unlock() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-14 15:26:50 +08:00
										 |  |  | // objectAPIHandlers implements and provides http handlers for S3 API.
 | 
					
						
							| 
									
										
										
										
											2016-04-13 03:45:15 +08:00
										 |  |  | type objectAPIHandlers struct { | 
					
						
							| 
									
										
										
										
											2016-08-01 05:11:14 +08:00
										 |  |  | 	ObjectAPI func() ObjectLayer | 
					
						
							| 
									
										
										
										
											2016-03-28 03:37:21 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-10 00:57:37 +08: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 14:19:36 +08:00
										 |  |  | func notImplementedHandler(w http.ResponseWriter, r *http.Request) { | 
					
						
							| 
									
										
										
										
											2021-06-18 11:27:04 +08:00
										 |  |  | 	writeErrorResponse(r.Context(), w, errorCodes.ToAPIErr(ErrNotImplemented), r.URL) | 
					
						
							| 
									
										
										
										
											2021-03-31 14:19:36 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type rejectedAPI struct { | 
					
						
							|  |  |  | 	api     string | 
					
						
							|  |  |  | 	methods []string | 
					
						
							|  |  |  | 	queries []string | 
					
						
							|  |  |  | 	path    string | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-20 00:21:34 +08: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 14:19:36 +08: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", ""}, | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | // Set of s3 handler options as bit flags.
 | 
					
						
							|  |  |  | type s3HFlag uint8 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const ( | 
					
						
							|  |  |  | 	// when provided, disables Gzip compression.
 | 
					
						
							|  |  |  | 	noGZS3HFlag = 1 << iota | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// when provided, enables only tracing of headers. Otherwise, both headers
 | 
					
						
							|  |  |  | 	// and body are traced.
 | 
					
						
							|  |  |  | 	traceHdrsS3HFlag | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// when provided, disables throttling via the `maxClients` middleware.
 | 
					
						
							|  |  |  | 	noThrottleS3HFlag | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (h s3HFlag) has(flag s3HFlag) bool { | 
					
						
							|  |  |  | 	// Use bitwise-AND and check if the result is non-zero.
 | 
					
						
							|  |  |  | 	return h&flag != 0 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // s3APIMiddleware - performs some common handler functionality for S3 API
 | 
					
						
							|  |  |  | // handlers.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // It is set per-"handler function registration" in the router to allow for
 | 
					
						
							|  |  |  | // behavior modification via flags.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // This middleware always calls `collectAPIStats` to collect API stats.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // The passed in handler function must be a method of `objectAPIHandlers` for
 | 
					
						
							|  |  |  | // the name displayed in logs and trace to be accurate. The name is extracted
 | 
					
						
							|  |  |  | // via reflection.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // When **no** flags are passed, the behavior is to trace both headers and body,
 | 
					
						
							|  |  |  | // gzip the response and throttle the handler via `maxClients`. Each of these
 | 
					
						
							|  |  |  | // can be disabled via the corresponding `s3HFlag`.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // CAUTION: for requests involving large req/resp bodies ensure to pass the
 | 
					
						
							|  |  |  | // `traceHdrsS3HFlag`, otherwise both headers and body will be traced, causing
 | 
					
						
							|  |  |  | // high memory usage!
 | 
					
						
							|  |  |  | func s3APIMiddleware(f http.HandlerFunc, flags ...s3HFlag) http.HandlerFunc { | 
					
						
							|  |  |  | 	// Collect all flags with bitwise-OR and assign operator
 | 
					
						
							|  |  |  | 	var handlerFlags s3HFlag | 
					
						
							|  |  |  | 	for _, flag := range flags { | 
					
						
							|  |  |  | 		handlerFlags |= flag | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Get name of the handler using reflection.
 | 
					
						
							|  |  |  | 	handlerName := getHandlerName(f, "objectAPIHandlers") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	var handler http.HandlerFunc = func(w http.ResponseWriter, r *http.Request) { | 
					
						
							|  |  |  | 		// Wrap the actual handler with the appropriate tracing middleware.
 | 
					
						
							|  |  |  | 		var tracedHandler http.HandlerFunc | 
					
						
							|  |  |  | 		if handlerFlags.has(traceHdrsS3HFlag) { | 
					
						
							|  |  |  | 			tracedHandler = httpTraceHdrs(f) | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			tracedHandler = httpTraceAll(f) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Skip wrapping with the gzip middleware if specified.
 | 
					
						
							|  |  |  | 		var gzippedHandler http.HandlerFunc = tracedHandler | 
					
						
							|  |  |  | 		if !handlerFlags.has(noGZS3HFlag) { | 
					
						
							|  |  |  | 			gzippedHandler = gzipHandler(gzippedHandler) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Skip wrapping with throttling middleware if specified.
 | 
					
						
							|  |  |  | 		var throttledHandler http.HandlerFunc = gzippedHandler | 
					
						
							|  |  |  | 		if !handlerFlags.has(noThrottleS3HFlag) { | 
					
						
							|  |  |  | 			throttledHandler = maxClients(throttledHandler) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Collect API stats using the API name got from reflection in
 | 
					
						
							|  |  |  | 		// `getHandlerName`.
 | 
					
						
							|  |  |  | 		statsCollectedHandler := collectAPIStats(handlerName, throttledHandler) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Call the final handler.
 | 
					
						
							|  |  |  | 		statsCollectedHandler(w, r) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return handler | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-28 03:37:21 +08:00
										 |  |  | // registerAPIRouter - registers S3 compatible APIs.
 | 
					
						
							| 
									
										
										
										
											2020-09-16 04:57:15 +08:00
										 |  |  | func registerAPIRouter(router *mux.Router) { | 
					
						
							| 
									
										
										
										
											2016-10-06 03:48:07 +08:00
										 |  |  | 	// Initialize API.
 | 
					
						
							|  |  |  | 	api := objectAPIHandlers{ | 
					
						
							| 
									
										
										
										
											2019-11-10 01:27:23 +08:00
										 |  |  | 		ObjectAPI: newObjectLayerFn, | 
					
						
							| 
									
										
										
										
											2016-10-06 03:48:07 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-28 03:37:21 +08:00
										 |  |  | 	// API Router
 | 
					
						
							| 
									
										
										
										
											2019-08-07 03:08:58 +08:00
										 |  |  | 	apiRouter := router.PathPrefix(SlashSeparator).Subrouter() | 
					
						
							| 
									
										
										
										
											2020-09-10 00:57:37 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-22 10:23:54 +08:00
										 |  |  | 	var routers []*mux.Router | 
					
						
							| 
									
										
										
										
											2019-02-23 11:18:01 +08:00
										 |  |  | 	for _, domainName := range globalDomainNames { | 
					
						
							| 
									
										
										
										
											2020-09-10 00:57:37 +08:00
										 |  |  | 		if IsKubernetes() { | 
					
						
							|  |  |  | 			routers = append(routers, apiRouter.MatcherFunc(func(r *http.Request, match *mux.RouteMatch) bool { | 
					
						
							| 
									
										
										
										
											2020-09-24 03:10:09 +08:00
										 |  |  | 				host, _, err := net.SplitHostPort(getHost(r)) | 
					
						
							|  |  |  | 				if err != nil { | 
					
						
							|  |  |  | 					host = r.Host | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2020-09-10 00:57:37 +08: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 08:56:24 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	routers = append(routers, apiRouter.PathPrefix("/{bucket}").Subrouter()) | 
					
						
							| 
									
										
										
										
											2016-03-28 03:37:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-31 14:19:36 +08:00
										 |  |  | 	for _, router := range routers { | 
					
						
							| 
									
										
										
										
											2021-05-20 00:21:34 +08: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 08:56:24 +08:00
										 |  |  | 		// Object operations
 | 
					
						
							|  |  |  | 		// HeadObject
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodHead).Path("/{object:.+}"). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.HeadObjectHandler)) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-04 06:03:51 +08:00
										 |  |  | 		// GetObjectAttributes
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodGet).Path("/{object:.+}"). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.GetObjectAttributesHandler, traceHdrsS3HFlag)). | 
					
						
							|  |  |  | 			Queries("attributes", "") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 		// CopyObjectPart
 | 
					
						
							| 
									
										
										
										
											2021-03-31 14:19:36 +08:00
										 |  |  | 		router.Methods(http.MethodPut).Path("/{object:.+}"). | 
					
						
							| 
									
										
										
										
											2020-09-10 00:57:37 +08:00
										 |  |  | 			HeadersRegexp(xhttp.AmzCopySource, ".*?(\\/|%2F).*?"). | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 			HandlerFunc(s3APIMiddleware(api.CopyObjectPartHandler)). | 
					
						
							| 
									
										
										
										
											2023-05-24 23:00:47 +08:00
										 |  |  | 			Queries("partNumber", "{partNumber:.*}", "uploadId", "{uploadId:.*}") | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 		// PutObjectPart
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodPut).Path("/{object:.+}"). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.PutObjectPartHandler, traceHdrsS3HFlag)). | 
					
						
							|  |  |  | 			Queries("partNumber", "{partNumber:.*}", "uploadId", "{uploadId:.*}") | 
					
						
							| 
									
										
										
										
											2019-08-20 05:02:54 +08:00
										 |  |  | 		// ListObjectParts
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodGet).Path("/{object:.+}"). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.ListObjectPartsHandler)). | 
					
						
							|  |  |  | 			Queries("uploadId", "{uploadId:.*}") | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 		// CompleteMultipartUpload
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodPost).Path("/{object:.+}"). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.CompleteMultipartUploadHandler)). | 
					
						
							|  |  |  | 			Queries("uploadId", "{uploadId:.*}") | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 		// NewMultipartUpload
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodPost).Path("/{object:.+}"). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.NewMultipartUploadHandler)). | 
					
						
							|  |  |  | 			Queries("uploads", "") | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 		// AbortMultipartUpload
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodDelete).Path("/{object:.+}"). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.AbortMultipartUploadHandler)). | 
					
						
							|  |  |  | 			Queries("uploadId", "{uploadId:.*}") | 
					
						
							| 
									
										
										
										
											2018-06-01 10:43:50 +08:00
										 |  |  | 		// GetObjectACL - this is a dummy call.
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodGet).Path("/{object:.+}"). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.GetObjectACLHandler, traceHdrsS3HFlag)). | 
					
						
							|  |  |  | 			Queries("acl", "") | 
					
						
							| 
									
										
										
										
											2020-02-16 14:07:52 +08:00
										 |  |  | 		// PutObjectACL - this is a dummy call.
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodPut).Path("/{object:.+}"). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.PutObjectACLHandler, traceHdrsS3HFlag)). | 
					
						
							|  |  |  | 			Queries("acl", "") | 
					
						
							| 
									
										
										
										
											2020-01-21 00:45:59 +08:00
										 |  |  | 		// GetObjectTagging
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodGet).Path("/{object:.+}"). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.GetObjectTaggingHandler, traceHdrsS3HFlag)). | 
					
						
							|  |  |  | 			Queries("tagging", "") | 
					
						
							| 
									
										
										
										
											2020-01-21 00:45:59 +08:00
										 |  |  | 		// PutObjectTagging
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodPut).Path("/{object:.+}"). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.PutObjectTaggingHandler, traceHdrsS3HFlag)). | 
					
						
							|  |  |  | 			Queries("tagging", "") | 
					
						
							| 
									
										
										
										
											2020-01-21 00:45:59 +08:00
										 |  |  | 		// DeleteObjectTagging
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodDelete).Path("/{object:.+}"). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.DeleteObjectTaggingHandler, traceHdrsS3HFlag)). | 
					
						
							|  |  |  | 			Queries("tagging", "") | 
					
						
							| 
									
										
										
										
											2018-08-15 18:30:19 +08:00
										 |  |  | 		// SelectObjectContent
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodPost).Path("/{object:.+}"). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.SelectObjectContentHandler, traceHdrsS3HFlag)). | 
					
						
							|  |  |  | 			Queries("select", "").Queries("select-type", "2") | 
					
						
							| 
									
										
										
										
											2019-11-21 05:18:09 +08:00
										 |  |  | 		// GetObjectRetention
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodGet).Path("/{object:.+}"). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.GetObjectRetentionHandler)). | 
					
						
							|  |  |  | 			Queries("retention", "") | 
					
						
							| 
									
										
										
										
											2020-01-17 07:41:56 +08:00
										 |  |  | 		// GetObjectLegalHold
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodGet).Path("/{object:.+}"). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.GetObjectLegalHoldHandler)). | 
					
						
							|  |  |  | 			Queries("legal-hold", "") | 
					
						
							| 
									
										
										
										
											2023-03-08 00:12:41 +08:00
										 |  |  | 		// GetObject with lambda ARNs
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodGet).Path("/{object:.+}"). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.GetObjectLambdaHandler, traceHdrsS3HFlag)). | 
					
						
							|  |  |  | 			Queries("lambdaArn", "{lambdaArn:.*}") | 
					
						
							| 
									
										
										
										
											2023-03-08 00:12:41 +08:00
										 |  |  | 		// GetObject
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodGet).Path("/{object:.+}"). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.GetObjectHandler, traceHdrsS3HFlag)) | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 		// CopyObject
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodPut).Path("/{object:.+}"). | 
					
						
							|  |  |  | 			HeadersRegexp(xhttp.AmzCopySource, ".*?(\\/|%2F).*?"). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.CopyObjectHandler)) | 
					
						
							| 
									
										
										
										
											2019-11-21 05:18:09 +08:00
										 |  |  | 		// PutObjectRetention
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodPut).Path("/{object:.+}"). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.PutObjectRetentionHandler)). | 
					
						
							|  |  |  | 			Queries("retention", "") | 
					
						
							| 
									
										
										
										
											2020-01-17 07:41:56 +08:00
										 |  |  | 		// PutObjectLegalHold
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodPut).Path("/{object:.+}"). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.PutObjectLegalHoldHandler)). | 
					
						
							|  |  |  | 			Queries("legal-hold", "") | 
					
						
							| 
									
										
										
										
											2020-01-17 07:41:56 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-27 08:15:09 +08:00
										 |  |  | 		// PutObject with auto-extract support for zip
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodPut).Path("/{object:.+}"). | 
					
						
							|  |  |  | 			HeadersRegexp(xhttp.AmzSnowballExtract, "true"). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.PutObjectExtractHandler, traceHdrsS3HFlag)) | 
					
						
							| 
									
										
										
										
											2021-03-27 08:15:09 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 		// PutObject
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodPut).Path("/{object:.+}"). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.PutObjectHandler, traceHdrsS3HFlag)) | 
					
						
							| 
									
										
										
										
											2021-03-27 08:15:09 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 		// DeleteObject
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodDelete).Path("/{object:.+}"). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.DeleteObjectHandler)) | 
					
						
							| 
									
										
										
										
											2016-03-28 03:37:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-02 15:10:33 +08:00
										 |  |  | 		// PostRestoreObject
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodPost).Path("/{object:.+}"). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.PostRestoreObjectHandler)). | 
					
						
							|  |  |  | 			Queries("restore", "") | 
					
						
							| 
									
										
										
										
											2021-03-02 15:10:33 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-17 01:28:29 +08:00
										 |  |  | 		// Bucket operations
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 		// GetBucketLocation
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodGet). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.GetBucketLocationHandler)). | 
					
						
							|  |  |  | 			Queries("location", "") | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 		// GetBucketPolicy
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodGet). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.GetBucketPolicyHandler)). | 
					
						
							|  |  |  | 			Queries("policy", "") | 
					
						
							| 
									
										
										
										
											2019-07-20 04:20:33 +08:00
										 |  |  | 		// GetBucketLifecycle
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodGet). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.GetBucketLifecycleHandler)). | 
					
						
							|  |  |  | 			Queries("lifecycle", "") | 
					
						
							| 
									
										
										
										
											2020-02-05 17:42:34 +08:00
										 |  |  | 		// GetBucketEncryption
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodGet). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.GetBucketEncryptionHandler)). | 
					
						
							|  |  |  | 			Queries("encryption", "") | 
					
						
							| 
									
										
										
										
											2020-07-22 08:49:56 +08:00
										 |  |  | 		// GetBucketObjectLockConfig
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodGet). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.GetBucketObjectLockConfigHandler)). | 
					
						
							|  |  |  | 			Queries("object-lock", "") | 
					
						
							| 
									
										
										
										
											2020-07-22 08:49:56 +08:00
										 |  |  | 		// GetBucketReplicationConfig
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodGet). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.GetBucketReplicationConfigHandler)). | 
					
						
							|  |  |  | 			Queries("replication", "") | 
					
						
							| 
									
										
										
										
											2020-07-22 08:49:56 +08:00
										 |  |  | 		// GetBucketVersioning
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodGet). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.GetBucketVersioningHandler)). | 
					
						
							|  |  |  | 			Queries("versioning", "") | 
					
						
							| 
									
										
										
										
											2020-07-22 08:49:56 +08:00
										 |  |  | 		// GetBucketNotification
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodGet). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.GetBucketNotificationHandler)). | 
					
						
							|  |  |  | 			Queries("notification", "") | 
					
						
							| 
									
										
										
										
											2020-07-22 08:49:56 +08:00
										 |  |  | 		// ListenNotification
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodGet). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.ListenNotificationHandler, noThrottleS3HFlag)). | 
					
						
							|  |  |  | 			Queries("events", "{events:.*}") | 
					
						
							| 
									
										
										
										
											2022-02-11 02:16:52 +08:00
										 |  |  | 		// ResetBucketReplicationStatus - MinIO extension API
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodGet). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.ResetBucketReplicationStatusHandler)). | 
					
						
							|  |  |  | 			Queries("replication-reset-status", "") | 
					
						
							| 
									
										
										
										
											2018-05-10 12:02:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-09 08:18:13 +08:00
										 |  |  | 		// Dummy Bucket Calls
 | 
					
						
							| 
									
										
										
										
											2018-05-10 12:02:26 +08:00
										 |  |  | 		// GetBucketACL -- this is a dummy call.
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodGet). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.GetBucketACLHandler)). | 
					
						
							|  |  |  | 			Queries("acl", "") | 
					
						
							| 
									
										
										
										
											2020-02-16 14:07:52 +08:00
										 |  |  | 		// PutBucketACL -- this is a dummy call.
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodPut). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.PutBucketACLHandler)). | 
					
						
							|  |  |  | 			Queries("acl", "") | 
					
						
							| 
									
										
										
										
											2019-02-09 08:18:13 +08:00
										 |  |  | 		// GetBucketCors - this is a dummy call.
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodGet). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.GetBucketCorsHandler)). | 
					
						
							|  |  |  | 			Queries("cors", "") | 
					
						
							| 
									
										
										
										
											2019-02-09 08:18:13 +08:00
										 |  |  | 		// GetBucketWebsiteHandler - this is a dummy call.
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodGet). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.GetBucketWebsiteHandler)). | 
					
						
							|  |  |  | 			Queries("website", "") | 
					
						
							| 
									
										
										
										
											2019-02-09 08:18:13 +08:00
										 |  |  | 		// GetBucketAccelerateHandler - this is a dummy call.
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodGet). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.GetBucketAccelerateHandler)). | 
					
						
							|  |  |  | 			Queries("accelerate", "") | 
					
						
							| 
									
										
										
										
											2019-02-09 08:18:13 +08:00
										 |  |  | 		// GetBucketRequestPaymentHandler - this is a dummy call.
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodGet). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.GetBucketRequestPaymentHandler)). | 
					
						
							|  |  |  | 			Queries("requestPayment", "") | 
					
						
							| 
									
										
										
										
											2019-02-09 08:18:13 +08:00
										 |  |  | 		// GetBucketLoggingHandler - this is a dummy call.
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodGet). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.GetBucketLoggingHandler)). | 
					
						
							|  |  |  | 			Queries("logging", "") | 
					
						
							| 
									
										
										
										
											2020-05-06 05:18:13 +08:00
										 |  |  | 		// GetBucketTaggingHandler
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodGet). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.GetBucketTaggingHandler)). | 
					
						
							|  |  |  | 			Queries("tagging", "") | 
					
						
							| 
									
										
										
										
											2021-11-17 01:28:29 +08:00
										 |  |  | 		// DeleteBucketWebsiteHandler
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodDelete). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.DeleteBucketWebsiteHandler)). | 
					
						
							|  |  |  | 			Queries("website", "") | 
					
						
							| 
									
										
										
										
											2019-02-09 08:18:13 +08:00
										 |  |  | 		// DeleteBucketTaggingHandler
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodDelete). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.DeleteBucketTaggingHandler)). | 
					
						
							|  |  |  | 			Queries("tagging", "") | 
					
						
							| 
									
										
										
										
											2018-05-10 12:02:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 		// ListMultipartUploads
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodGet). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.ListMultipartUploadsHandler)). | 
					
						
							|  |  |  | 			Queries("uploads", "") | 
					
						
							| 
									
										
										
										
											2019-11-21 17:54:49 +08:00
										 |  |  | 		// ListObjectsV2M
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodGet). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.ListObjectsV2MHandler)). | 
					
						
							|  |  |  | 			Queries("list-type", "2", "metadata", "true") | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 		// ListObjectsV2
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodGet). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.ListObjectsV2Handler)). | 
					
						
							|  |  |  | 			Queries("list-type", "2") | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 		// ListObjectVersions
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodGet). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.ListObjectVersionsMHandler)). | 
					
						
							|  |  |  | 			Queries("versions", "", "metadata", "true") | 
					
						
							| 
									
										
										
										
											2023-03-31 03:20:42 +08:00
										 |  |  | 		// ListObjectVersions
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodGet). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.ListObjectVersionsHandler)). | 
					
						
							|  |  |  | 			Queries("versions", "") | 
					
						
							| 
									
										
										
										
											2021-03-02 15:10:33 +08:00
										 |  |  | 		// GetBucketPolicyStatus
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodGet). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.GetBucketPolicyStatusHandler)). | 
					
						
							|  |  |  | 			Queries("policyStatus", "") | 
					
						
							| 
									
										
										
										
											2019-07-20 04:20:33 +08:00
										 |  |  | 		// PutBucketLifecycle
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodPut). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.PutBucketLifecycleHandler)). | 
					
						
							|  |  |  | 			Queries("lifecycle", "") | 
					
						
							| 
									
										
										
										
											2020-07-22 08:49:56 +08:00
										 |  |  | 		// PutBucketReplicationConfig
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodPut). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.PutBucketReplicationConfigHandler)). | 
					
						
							|  |  |  | 			Queries("replication", "") | 
					
						
							| 
									
										
										
										
											2020-02-05 17:42:34 +08:00
										 |  |  | 		// PutBucketEncryption
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodPut). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.PutBucketEncryptionHandler)). | 
					
						
							|  |  |  | 			Queries("encryption", "") | 
					
						
							| 
									
										
										
										
											2020-02-05 17:42:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 		// PutBucketPolicy
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodPut). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.PutBucketPolicyHandler)). | 
					
						
							|  |  |  | 			Queries("policy", "") | 
					
						
							| 
									
										
										
										
											2019-07-20 04:20:33 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-13 06:50:18 +08:00
										 |  |  | 		// PutBucketObjectLockConfig
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodPut). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.PutBucketObjectLockConfigHandler)). | 
					
						
							|  |  |  | 			Queries("object-lock", "") | 
					
						
							| 
									
										
										
										
											2020-05-06 05:18:13 +08:00
										 |  |  | 		// PutBucketTaggingHandler
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodPut). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.PutBucketTaggingHandler)). | 
					
						
							|  |  |  | 			Queries("tagging", "") | 
					
						
							| 
									
										
										
										
											2019-11-13 06:50:18 +08:00
										 |  |  | 		// PutBucketVersioning
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodPut). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.PutBucketVersioningHandler)). | 
					
						
							|  |  |  | 			Queries("versioning", "") | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 		// PutBucketNotification
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodPut). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.PutBucketNotificationHandler)). | 
					
						
							|  |  |  | 			Queries("notification", "") | 
					
						
							| 
									
										
										
										
											2022-02-11 02:16:52 +08:00
										 |  |  | 		// ResetBucketReplicationStart - MinIO extension API
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodPut). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.ResetBucketReplicationStartHandler)). | 
					
						
							|  |  |  | 			Queries("replication-reset", "") | 
					
						
							| 
									
										
										
										
											2022-02-11 02:16:52 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 		// PutBucket
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodPut). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.PutBucketHandler)) | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 		// HeadBucket
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodHead). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.HeadBucketHandler)) | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 		// PostPolicy
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodPost). | 
					
						
							|  |  |  | 			MatcherFunc(func(r *http.Request, _ *mux.RouteMatch) bool { | 
					
						
							|  |  |  | 				return isRequestPostPolicySignatureV4(r) | 
					
						
							|  |  |  | 			}). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.PostPolicyBucketHandler, traceHdrsS3HFlag)) | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 		// DeleteMultipleObjects
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodPost). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.DeleteMultipleObjectsHandler)). | 
					
						
							|  |  |  | 			Queries("delete", "") | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 		// DeleteBucketPolicy
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodDelete). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.DeleteBucketPolicyHandler)). | 
					
						
							|  |  |  | 			Queries("policy", "") | 
					
						
							| 
									
										
										
										
											2020-07-22 08:49:56 +08:00
										 |  |  | 		// DeleteBucketReplication
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodDelete). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.DeleteBucketReplicationConfigHandler)). | 
					
						
							|  |  |  | 			Queries("replication", "") | 
					
						
							| 
									
										
										
										
											2019-07-20 04:20:33 +08:00
										 |  |  | 		// DeleteBucketLifecycle
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodDelete). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.DeleteBucketLifecycleHandler)). | 
					
						
							|  |  |  | 			Queries("lifecycle", "") | 
					
						
							| 
									
										
										
										
											2020-02-05 17:42:34 +08:00
										 |  |  | 		// DeleteBucketEncryption
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodDelete). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.DeleteBucketEncryptionHandler)). | 
					
						
							|  |  |  | 			Queries("encryption", "") | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 		// DeleteBucket
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodDelete). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.DeleteBucketHandler)) | 
					
						
							| 
									
										
										
										
											2021-05-20 00:21:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-04 00:03:42 +08:00
										 |  |  | 		// MinIO extension API for replication.
 | 
					
						
							|  |  |  | 		//
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodGet). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.GetBucketReplicationMetricsV2Handler)). | 
					
						
							|  |  |  | 			Queries("replication-metrics", "2") | 
					
						
							| 
									
										
										
										
											2023-08-30 16:00:59 +08:00
										 |  |  | 		// deprecated handler
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodGet). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.GetBucketReplicationMetricsHandler)). | 
					
						
							|  |  |  | 			Queries("replication-metrics", "") | 
					
						
							| 
									
										
										
										
											2023-08-30 16:00:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-11 11:09:20 +08:00
										 |  |  | 		// ValidateBucketReplicationCreds
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodGet). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.ValidateBucketReplicationCredsHandler)). | 
					
						
							|  |  |  | 			Queries("replication-check", "") | 
					
						
							| 
									
										
										
										
											2021-04-06 04:36:39 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-20 00:21:34 +08:00
										 |  |  | 		// Register rejected bucket APIs
 | 
					
						
							|  |  |  | 		for _, r := range rejectedBucketAPIs { | 
					
						
							|  |  |  | 			router.Methods(r.methods...). | 
					
						
							|  |  |  | 				HandlerFunc(collectAPIStats(r.api, httpTraceAll(notImplementedHandler))). | 
					
						
							|  |  |  | 				Queries(r.queries...) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-06 04:36:39 +08:00
										 |  |  | 		// S3 ListObjectsV1 (Legacy)
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 		router.Methods(http.MethodGet). | 
					
						
							|  |  |  | 			HandlerFunc(s3APIMiddleware(api.ListObjectsV1Handler)) | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-03-28 03:37:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-17 01:28:29 +08:00
										 |  |  | 	// Root operation
 | 
					
						
							| 
									
										
										
										
											2016-03-28 03:37:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-21 03:52:49 +08:00
										 |  |  | 	// ListenNotification
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 	apiRouter.Methods(http.MethodGet).Path(SlashSeparator). | 
					
						
							|  |  |  | 		HandlerFunc(s3APIMiddleware(api.ListenNotificationHandler, noThrottleS3HFlag)). | 
					
						
							|  |  |  | 		Queries("events", "{events:.*}") | 
					
						
							| 
									
										
										
										
											2020-07-21 03:52:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-28 03:37:21 +08:00
										 |  |  | 	// ListBuckets
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 	apiRouter.Methods(http.MethodGet).Path(SlashSeparator). | 
					
						
							|  |  |  | 		HandlerFunc(s3APIMiddleware(api.ListBucketsHandler)) | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-22 09:51:23 +08:00
										 |  |  | 	// S3 browser with signature v4 adds '//' for ListBuckets request, so rather
 | 
					
						
							|  |  |  | 	// than failing with UnknownAPIRequest we simply handle it for now.
 | 
					
						
							| 
									
										
										
										
											2024-03-05 02:05:56 +08:00
										 |  |  | 	apiRouter.Methods(http.MethodGet).Path(SlashSeparator + SlashSeparator). | 
					
						
							|  |  |  | 		HandlerFunc(s3APIMiddleware(api.ListBucketsHandler)) | 
					
						
							| 
									
										
										
										
											2020-05-22 09:51:23 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-05 01:30:59 +08:00
										 |  |  | 	// If none of the routes match add default error handler routes
 | 
					
						
							| 
									
										
										
										
											2020-09-29 04:33:49 +08:00
										 |  |  | 	apiRouter.NotFoundHandler = collectAPIStats("notfound", httpTraceAll(errorResponseHandler)) | 
					
						
							| 
									
										
										
										
											2020-10-29 00:18:35 +08:00
										 |  |  | 	apiRouter.MethodNotAllowedHandler = collectAPIStats("methodnotallowed", httpTraceAll(methodNotAllowedHandler("S3"))) | 
					
						
							| 
									
										
										
										
											2016-03-28 03:37:21 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-07-07 11:55:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-13 01:56:57 +08:00
										 |  |  | // corsHandler handler for CORS (Cross Origin Resource Sharing)
 | 
					
						
							|  |  |  | func corsHandler(handler http.Handler) http.Handler { | 
					
						
							| 
									
										
										
										
											2020-07-07 11:55:19 +08:00
										 |  |  | 	commonS3Headers := []string{ | 
					
						
							|  |  |  | 		xhttp.Date, | 
					
						
							|  |  |  | 		xhttp.ETag, | 
					
						
							|  |  |  | 		xhttp.ServerInfo, | 
					
						
							|  |  |  | 		xhttp.Connection, | 
					
						
							|  |  |  | 		xhttp.AcceptRanges, | 
					
						
							|  |  |  | 		xhttp.ContentRange, | 
					
						
							|  |  |  | 		xhttp.ContentEncoding, | 
					
						
							|  |  |  | 		xhttp.ContentLength, | 
					
						
							|  |  |  | 		xhttp.ContentType, | 
					
						
							| 
									
										
										
										
											2020-07-28 00:03:38 +08:00
										 |  |  | 		xhttp.ContentDisposition, | 
					
						
							| 
									
										
										
										
											2020-07-24 15:46:51 +08:00
										 |  |  | 		xhttp.LastModified, | 
					
						
							|  |  |  | 		xhttp.ContentLanguage, | 
					
						
							|  |  |  | 		xhttp.CacheControl, | 
					
						
							|  |  |  | 		xhttp.RetryAfter, | 
					
						
							|  |  |  | 		xhttp.AmzBucketRegion, | 
					
						
							|  |  |  | 		xhttp.Expires, | 
					
						
							| 
									
										
										
										
											2020-07-07 11:55:19 +08:00
										 |  |  | 		"X-Amz*", | 
					
						
							|  |  |  | 		"x-amz*", | 
					
						
							|  |  |  | 		"*", | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2023-07-16 03:15:06 +08:00
										 |  |  | 	opts := cors.Options{ | 
					
						
							| 
									
										
										
										
											2020-07-07 11:55:19 +08:00
										 |  |  | 		AllowOriginFunc: func(origin string) bool { | 
					
						
							| 
									
										
										
										
											2023-07-16 03:15:06 +08:00
										 |  |  | 			for _, allowedOrigin := range globalAPIConfig.getCorsAllowOrigins() { | 
					
						
							| 
									
										
										
										
											2020-07-07 11:55:19 +08: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, | 
					
						
							| 
									
										
										
										
											2023-07-16 03:15:06 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return cors.New(opts).Handler(handler) | 
					
						
							| 
									
										
										
										
											2020-07-07 11:55:19 +08:00
										 |  |  | } |