| 
									
										
										
										
											2016-03-28 03:37:21 +08:00
										 |  |  | /* | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  |  * MinIO Cloud Storage, (C) 2016-2020 MinIO, Inc. | 
					
						
							| 
									
										
										
										
											2016-03-28 03:37:21 +08:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Licensed under the Apache License, Version 2.0 (the "License"); | 
					
						
							|  |  |  |  * you may not use this file except in compliance with the License. | 
					
						
							|  |  |  |  * You may obtain a copy of the License at | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *     http://www.apache.org/licenses/LICENSE-2.0
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Unless required by applicable law or agreed to in writing, software | 
					
						
							|  |  |  |  * distributed under the License is distributed on an "AS IS" BASIS, | 
					
						
							|  |  |  |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
					
						
							|  |  |  |  * See the License for the specific language governing permissions and | 
					
						
							|  |  |  |  * limitations under the License. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-22 10:23:54 +08:00
										 |  |  | 	"github.com/gorilla/mux" | 
					
						
							| 
									
										
										
										
											2019-07-03 13:34:32 +08:00
										 |  |  | 	xhttp "github.com/minio/minio/cmd/http" | 
					
						
							| 
									
										
										
										
											2020-07-07 11:55:19 +08:00
										 |  |  | 	"github.com/minio/minio/pkg/wildcard" | 
					
						
							|  |  |  | 	"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 { | 
					
						
							|  |  |  | 	globalObjLayerMutex.Lock() | 
					
						
							|  |  |  | 	defer globalObjLayerMutex.Unlock() | 
					
						
							|  |  |  | 	return globalHTTPServer | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-10 01:27:23 +08:00
										 |  |  | func newObjectLayerFn() ObjectLayer { | 
					
						
							|  |  |  | 	globalObjLayerMutex.Lock() | 
					
						
							|  |  |  | 	defer globalObjLayerMutex.Unlock() | 
					
						
							|  |  |  | 	return globalObjectAPI | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func newCachedObjectLayerFn() CacheObjectLayer { | 
					
						
							|  |  |  | 	globalObjLayerMutex.Lock() | 
					
						
							|  |  |  | 	defer globalObjLayerMutex.Unlock() | 
					
						
							|  |  |  | 	return globalCacheObjectAPI | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-29 00:18:35 +08:00
										 |  |  | func setObjectLayer(o ObjectLayer) { | 
					
						
							|  |  |  | 	globalObjLayerMutex.Lock() | 
					
						
							|  |  |  | 	globalObjectAPI = o | 
					
						
							|  |  |  | 	globalObjLayerMutex.Unlock() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-13 03:45:15 +08:00
										 |  |  | // objectAPIHandler implements and provides http handlers for S3 API.
 | 
					
						
							|  |  |  | type objectAPIHandlers struct { | 
					
						
							| 
									
										
										
										
											2016-08-01 05:11:14 +08:00
										 |  |  | 	ObjectAPI func() ObjectLayer | 
					
						
							| 
									
										
										
										
											2018-03-29 05:14:06 +08:00
										 |  |  | 	CacheAPI  func() CacheObjectLayer | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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, | 
					
						
							|  |  |  | 		CacheAPI:  newCachedObjectLayerFn, | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 	for _, bucket := range routers { | 
					
						
							|  |  |  | 		// Object operations
 | 
					
						
							|  |  |  | 		// HeadObject
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodHead).Path("/{object:.+}").HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("headobject", httpTraceAll(api.HeadObjectHandler)))) | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 		// CopyObjectPart
 | 
					
						
							| 
									
										
										
										
											2020-09-10 00:57:37 +08:00
										 |  |  | 		bucket.Methods(http.MethodPut).Path("/{object:.+}"). | 
					
						
							|  |  |  | 			HeadersRegexp(xhttp.AmzCopySource, ".*?(\\/|%2F).*?"). | 
					
						
							|  |  |  | 			HandlerFunc(maxClients(collectAPIStats("copyobjectpart", httpTraceAll(api.CopyObjectPartHandler)))). | 
					
						
							|  |  |  | 			Queries("partNumber", "{partNumber:[0-9]+}", "uploadId", "{uploadId:.*}") | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 		// PutObjectPart
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodPut).Path("/{object:.+}").HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("putobjectpart", httpTraceHdrs(api.PutObjectPartHandler)))).Queries("partNumber", "{partNumber:[0-9]+}", "uploadId", "{uploadId:.*}") | 
					
						
							| 
									
										
										
										
											2019-08-20 05:02:54 +08:00
										 |  |  | 		// ListObjectParts
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodGet).Path("/{object:.+}").HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("listobjectparts", httpTraceAll(api.ListObjectPartsHandler)))).Queries("uploadId", "{uploadId:.*}") | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 		// CompleteMultipartUpload
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodPost).Path("/{object:.+}").HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("completemutipartupload", httpTraceAll(api.CompleteMultipartUploadHandler)))).Queries("uploadId", "{uploadId:.*}") | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 		// NewMultipartUpload
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodPost).Path("/{object:.+}").HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("newmultipartupload", httpTraceAll(api.NewMultipartUploadHandler)))).Queries("uploads", "") | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 		// AbortMultipartUpload
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodDelete).Path("/{object:.+}").HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("abortmultipartupload", httpTraceAll(api.AbortMultipartUploadHandler)))).Queries("uploadId", "{uploadId:.*}") | 
					
						
							| 
									
										
										
										
											2018-06-01 10:43:50 +08:00
										 |  |  | 		// GetObjectACL - this is a dummy call.
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodGet).Path("/{object:.+}").HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("getobjectacl", httpTraceHdrs(api.GetObjectACLHandler)))).Queries("acl", "") | 
					
						
							| 
									
										
										
										
											2020-02-16 14:07:52 +08:00
										 |  |  | 		// PutObjectACL - this is a dummy call.
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodPut).Path("/{object:.+}").HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("putobjectacl", httpTraceHdrs(api.PutObjectACLHandler)))).Queries("acl", "") | 
					
						
							| 
									
										
										
										
											2020-01-21 00:45:59 +08:00
										 |  |  | 		// GetObjectTagging
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodGet).Path("/{object:.+}").HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("getobjecttagging", httpTraceHdrs(api.GetObjectTaggingHandler)))).Queries("tagging", "") | 
					
						
							| 
									
										
										
										
											2020-01-21 00:45:59 +08:00
										 |  |  | 		// PutObjectTagging
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodPut).Path("/{object:.+}").HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("putobjecttagging", httpTraceHdrs(api.PutObjectTaggingHandler)))).Queries("tagging", "") | 
					
						
							| 
									
										
										
										
											2020-01-21 00:45:59 +08:00
										 |  |  | 		// DeleteObjectTagging
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodDelete).Path("/{object:.+}").HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("deleteobjecttagging", httpTraceHdrs(api.DeleteObjectTaggingHandler)))).Queries("tagging", "") | 
					
						
							| 
									
										
										
										
											2018-08-15 18:30:19 +08:00
										 |  |  | 		// SelectObjectContent
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodPost).Path("/{object:.+}").HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("selectobjectcontent", httpTraceHdrs(api.SelectObjectContentHandler)))).Queries("select", "").Queries("select-type", "2") | 
					
						
							| 
									
										
										
										
											2019-11-21 05:18:09 +08:00
										 |  |  | 		// GetObjectRetention
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodGet).Path("/{object:.+}").HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("getobjectretention", httpTraceAll(api.GetObjectRetentionHandler)))).Queries("retention", "") | 
					
						
							| 
									
										
										
										
											2020-01-17 07:41:56 +08:00
										 |  |  | 		// GetObjectLegalHold
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodGet).Path("/{object:.+}").HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("getobjectlegalhold", httpTraceAll(api.GetObjectLegalHoldHandler)))).Queries("legal-hold", "") | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 		// GetObject
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodGet).Path("/{object:.+}").HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("getobject", httpTraceHdrs(api.GetObjectHandler)))) | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 		// CopyObject
 | 
					
						
							| 
									
										
										
										
											2020-09-10 00:57:37 +08:00
										 |  |  | 		bucket.Methods(http.MethodPut).Path("/{object:.+}").HeadersRegexp(xhttp.AmzCopySource, ".*?(\\/|%2F).*?"). | 
					
						
							|  |  |  | 			HandlerFunc(maxClients(collectAPIStats("copyobject", httpTraceAll(api.CopyObjectHandler)))) | 
					
						
							| 
									
										
										
										
											2019-11-21 05:18:09 +08:00
										 |  |  | 		// PutObjectRetention
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodPut).Path("/{object:.+}").HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("putobjectretention", httpTraceAll(api.PutObjectRetentionHandler)))).Queries("retention", "") | 
					
						
							| 
									
										
										
										
											2020-01-17 07:41:56 +08:00
										 |  |  | 		// PutObjectLegalHold
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodPut).Path("/{object:.+}").HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("putobjectlegalhold", httpTraceAll(api.PutObjectLegalHoldHandler)))).Queries("legal-hold", "") | 
					
						
							| 
									
										
										
										
											2020-01-17 07:41:56 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 		// PutObject
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodPut).Path("/{object:.+}").HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("putobject", httpTraceHdrs(api.PutObjectHandler)))) | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 		// DeleteObject
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodDelete).Path("/{object:.+}").HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("deleteobject", httpTraceAll(api.DeleteObjectHandler)))) | 
					
						
							| 
									
										
										
										
											2016-03-28 03:37:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 		/// Bucket operations
 | 
					
						
							|  |  |  | 		// GetBucketLocation
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodGet).HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("getbucketlocation", httpTraceAll(api.GetBucketLocationHandler)))).Queries("location", "") | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 		// GetBucketPolicy
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodGet).HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("getbucketpolicy", httpTraceAll(api.GetBucketPolicyHandler)))).Queries("policy", "") | 
					
						
							| 
									
										
										
										
											2019-07-20 04:20:33 +08:00
										 |  |  | 		// GetBucketLifecycle
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodGet).HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("getbucketlifecycle", httpTraceAll(api.GetBucketLifecycleHandler)))).Queries("lifecycle", "") | 
					
						
							| 
									
										
										
										
											2020-02-05 17:42:34 +08:00
										 |  |  | 		// GetBucketEncryption
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodGet).HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("getbucketencryption", httpTraceAll(api.GetBucketEncryptionHandler)))).Queries("encryption", "") | 
					
						
							| 
									
										
										
										
											2020-07-22 08:49:56 +08:00
										 |  |  | 		// GetBucketObjectLockConfig
 | 
					
						
							|  |  |  | 		bucket.Methods(http.MethodGet).HandlerFunc( | 
					
						
							|  |  |  | 			maxClients(collectAPIStats("getbucketobjectlockconfiguration", httpTraceAll(api.GetBucketObjectLockConfigHandler)))).Queries("object-lock", "") | 
					
						
							|  |  |  | 		// GetBucketReplicationConfig
 | 
					
						
							|  |  |  | 		bucket.Methods(http.MethodGet).HandlerFunc( | 
					
						
							|  |  |  | 			maxClients(collectAPIStats("getbucketreplicationconfiguration", httpTraceAll(api.GetBucketReplicationConfigHandler)))).Queries("replication", "") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// GetBucketVersioning
 | 
					
						
							|  |  |  | 		bucket.Methods(http.MethodGet).HandlerFunc( | 
					
						
							|  |  |  | 			maxClients(collectAPIStats("getbucketversioning", httpTraceAll(api.GetBucketVersioningHandler)))).Queries("versioning", "") | 
					
						
							|  |  |  | 		// GetBucketNotification
 | 
					
						
							|  |  |  | 		bucket.Methods(http.MethodGet).HandlerFunc( | 
					
						
							|  |  |  | 			maxClients(collectAPIStats("getbucketnotification", httpTraceAll(api.GetBucketNotificationHandler)))).Queries("notification", "") | 
					
						
							|  |  |  | 		// ListenNotification
 | 
					
						
							|  |  |  | 		bucket.Methods(http.MethodGet).HandlerFunc(collectAPIStats("listennotification", httpTraceAll(api.ListenNotificationHandler))).Queries("events", "{events:.*}") | 
					
						
							| 
									
										
										
										
											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.
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodGet).HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("getbucketacl", httpTraceAll(api.GetBucketACLHandler)))).Queries("acl", "") | 
					
						
							| 
									
										
										
										
											2020-02-16 14:07:52 +08:00
										 |  |  | 		// PutBucketACL -- this is a dummy call.
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodPut).HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("putbucketacl", httpTraceAll(api.PutBucketACLHandler)))).Queries("acl", "") | 
					
						
							| 
									
										
										
										
											2019-02-09 08:18:13 +08:00
										 |  |  | 		// GetBucketCors - this is a dummy call.
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodGet).HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("getbucketcors", httpTraceAll(api.GetBucketCorsHandler)))).Queries("cors", "") | 
					
						
							| 
									
										
										
										
											2019-02-09 08:18:13 +08:00
										 |  |  | 		// GetBucketWebsiteHandler - this is a dummy call.
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodGet).HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("getbucketwebsite", httpTraceAll(api.GetBucketWebsiteHandler)))).Queries("website", "") | 
					
						
							| 
									
										
										
										
											2019-02-09 08:18:13 +08:00
										 |  |  | 		// GetBucketAccelerateHandler - this is a dummy call.
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodGet).HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("getbucketaccelerate", httpTraceAll(api.GetBucketAccelerateHandler)))).Queries("accelerate", "") | 
					
						
							| 
									
										
										
										
											2019-02-09 08:18:13 +08:00
										 |  |  | 		// GetBucketRequestPaymentHandler - this is a dummy call.
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodGet).HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("getbucketrequestpayment", httpTraceAll(api.GetBucketRequestPaymentHandler)))).Queries("requestPayment", "") | 
					
						
							| 
									
										
										
										
											2019-02-09 08:18:13 +08:00
										 |  |  | 		// GetBucketLoggingHandler - this is a dummy call.
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodGet).HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("getbucketlogging", httpTraceAll(api.GetBucketLoggingHandler)))).Queries("logging", "") | 
					
						
							| 
									
										
										
										
											2019-02-09 08:18:13 +08:00
										 |  |  | 		// GetBucketLifecycleHandler - this is a dummy call.
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodGet).HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("getbucketlifecycle", httpTraceAll(api.GetBucketLifecycleHandler)))).Queries("lifecycle", "") | 
					
						
							| 
									
										
										
										
											2020-05-06 05:18:13 +08:00
										 |  |  | 		// GetBucketTaggingHandler
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodGet).HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("getbuckettagging", httpTraceAll(api.GetBucketTaggingHandler)))).Queries("tagging", "") | 
					
						
							| 
									
										
										
										
											2019-02-09 08:18:13 +08:00
										 |  |  | 		//DeleteBucketWebsiteHandler
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodDelete).HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("deletebucketwebsite", httpTraceAll(api.DeleteBucketWebsiteHandler)))).Queries("website", "") | 
					
						
							| 
									
										
										
										
											2019-02-09 08:18:13 +08:00
										 |  |  | 		// DeleteBucketTaggingHandler
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodDelete).HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("deletebuckettagging", httpTraceAll(api.DeleteBucketTaggingHandler)))).Queries("tagging", "") | 
					
						
							| 
									
										
										
										
											2018-05-10 12:02:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 		// ListMultipartUploads
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodGet).HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("listmultipartuploads", httpTraceAll(api.ListMultipartUploadsHandler)))).Queries("uploads", "") | 
					
						
							| 
									
										
										
										
											2019-11-21 17:54:49 +08:00
										 |  |  | 		// ListObjectsV2M
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodGet).HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("listobjectsv2M", httpTraceAll(api.ListObjectsV2MHandler)))).Queries("list-type", "2", "metadata", "true") | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 		// ListObjectsV2
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodGet).HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("listobjectsv2", httpTraceAll(api.ListObjectsV2Handler)))).Queries("list-type", "2") | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 		// ListObjectVersions
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodGet).HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 			maxClients(collectAPIStats("listobjectversions", httpTraceAll(api.ListObjectVersionsHandler)))).Queries("versions", "") | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 		// ListObjectsV1 (Legacy)
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodGet).HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("listobjectsv1", httpTraceAll(api.ListObjectsV1Handler)))) | 
					
						
							| 
									
										
										
										
											2019-07-20 04:20:33 +08:00
										 |  |  | 		// PutBucketLifecycle
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodPut).HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("putbucketlifecycle", httpTraceAll(api.PutBucketLifecycleHandler)))).Queries("lifecycle", "") | 
					
						
							| 
									
										
										
										
											2020-07-22 08:49:56 +08:00
										 |  |  | 		// PutBucketReplicationConfig
 | 
					
						
							|  |  |  | 		bucket.Methods(http.MethodPut).HandlerFunc( | 
					
						
							|  |  |  | 			maxClients(collectAPIStats("putbucketreplicationconfiguration", httpTraceAll(api.PutBucketReplicationConfigHandler)))).Queries("replication", "") | 
					
						
							|  |  |  | 		// GetObjectRetention
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-05 17:42:34 +08:00
										 |  |  | 		// PutBucketEncryption
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodPut).HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("putbucketencryption", httpTraceAll(api.PutBucketEncryptionHandler)))).Queries("encryption", "") | 
					
						
							| 
									
										
										
										
											2020-02-05 17:42:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 		// PutBucketPolicy
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodPut).HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("putbucketpolicy", httpTraceAll(api.PutBucketPolicyHandler)))).Queries("policy", "") | 
					
						
							| 
									
										
										
										
											2019-07-20 04:20:33 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-13 06:50:18 +08:00
										 |  |  | 		// PutBucketObjectLockConfig
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodPut).HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("putbucketobjectlockconfig", httpTraceAll(api.PutBucketObjectLockConfigHandler)))).Queries("object-lock", "") | 
					
						
							| 
									
										
										
										
											2020-05-06 05:18:13 +08:00
										 |  |  | 		// PutBucketTaggingHandler
 | 
					
						
							|  |  |  | 		bucket.Methods(http.MethodPut).HandlerFunc( | 
					
						
							|  |  |  | 			maxClients(collectAPIStats("putbuckettagging", httpTraceAll(api.PutBucketTaggingHandler)))).Queries("tagging", "") | 
					
						
							| 
									
										
										
										
											2019-11-13 06:50:18 +08:00
										 |  |  | 		// PutBucketVersioning
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodPut).HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("putbucketversioning", httpTraceAll(api.PutBucketVersioningHandler)))).Queries("versioning", "") | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 		// PutBucketNotification
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodPut).HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("putbucketnotification", httpTraceAll(api.PutBucketNotificationHandler)))).Queries("notification", "") | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 		// PutBucket
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodPut).HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("putbucket", httpTraceAll(api.PutBucketHandler)))) | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 		// HeadBucket
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodHead).HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("headbucket", httpTraceAll(api.HeadBucketHandler)))) | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 		// PostPolicy
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodPost).HeadersRegexp(xhttp.ContentType, "multipart/form-data*").HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("postpolicybucket", httpTraceHdrs(api.PostPolicyBucketHandler)))) | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 		// DeleteMultipleObjects
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodPost).HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("deletemultipleobjects", httpTraceAll(api.DeleteMultipleObjectsHandler)))).Queries("delete", "") | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 		// DeleteBucketPolicy
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodDelete).HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("deletebucketpolicy", httpTraceAll(api.DeleteBucketPolicyHandler)))).Queries("policy", "") | 
					
						
							| 
									
										
										
										
											2020-07-22 08:49:56 +08:00
										 |  |  | 		// DeleteBucketReplication
 | 
					
						
							|  |  |  | 		bucket.Methods(http.MethodDelete).HandlerFunc( | 
					
						
							|  |  |  | 			maxClients(collectAPIStats("deletebucketreplicationconfiguration", httpTraceAll(api.DeleteBucketReplicationConfigHandler)))).Queries("replication", "") | 
					
						
							| 
									
										
										
										
											2019-07-20 04:20:33 +08:00
										 |  |  | 		// DeleteBucketLifecycle
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodDelete).HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("deletebucketlifecycle", httpTraceAll(api.DeleteBucketLifecycleHandler)))).Queries("lifecycle", "") | 
					
						
							| 
									
										
										
										
											2020-02-05 17:42:34 +08:00
										 |  |  | 		// DeleteBucketEncryption
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodDelete).HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("deletebucketencryption", httpTraceAll(api.DeleteBucketEncryptionHandler)))).Queries("encryption", "") | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 		// DeleteBucket
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 		bucket.Methods(http.MethodDelete).HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 			maxClients(collectAPIStats("deletebucket", httpTraceAll(api.DeleteBucketHandler)))) | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-03-28 03:37:21 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/// Root operation
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-21 03:52:49 +08:00
										 |  |  | 	// ListenNotification
 | 
					
						
							|  |  |  | 	apiRouter.Methods(http.MethodGet).Path(SlashSeparator).HandlerFunc( | 
					
						
							|  |  |  | 		collectAPIStats("listennotification", httpTraceAll(api.ListenNotificationHandler))).Queries("events", "{events:.*}") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-28 03:37:21 +08:00
										 |  |  | 	// ListBuckets
 | 
					
						
							| 
									
										
										
										
											2020-03-25 03:43:40 +08:00
										 |  |  | 	apiRouter.Methods(http.MethodGet).Path(SlashSeparator).HandlerFunc( | 
					
						
							| 
									
										
										
										
											2020-04-15 03:46:37 +08:00
										 |  |  | 		maxClients(collectAPIStats("listbuckets", httpTraceAll(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.
 | 
					
						
							|  |  |  | 	apiRouter.Methods(http.MethodGet).Path(SlashSeparator + SlashSeparator).HandlerFunc( | 
					
						
							|  |  |  | 		maxClients(collectAPIStats("listbuckets", httpTraceAll(api.ListBucketsHandler)))) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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"))) | 
					
						
							| 
									
										
										
										
											2019-11-05 01:30:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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*", | 
					
						
							|  |  |  | 		"*", | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-13 01:56:57 +08:00
										 |  |  | 	return cors.New(cors.Options{ | 
					
						
							| 
									
										
										
										
											2020-07-07 11:55:19 +08:00
										 |  |  | 		AllowOriginFunc: func(origin string) bool { | 
					
						
							|  |  |  | 			for _, allowedOrigin := range globalAPIConfig.getCorsAllowOrigins() { | 
					
						
							|  |  |  | 				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-13 01:56:57 +08:00
										 |  |  | 	}).Handler(handler) | 
					
						
							| 
									
										
										
										
											2020-07-07 11:55:19 +08:00
										 |  |  | } |