mirror of
https://github.com/DullJZ/s3-balance.git
synced 2026-07-03 09:01:22 +08:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d9258d4924 |
@@ -1,6 +1,7 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
"github.com/DullJZ/s3-balance/internal/balancer"
|
"github.com/DullJZ/s3-balance/internal/balancer"
|
||||||
@@ -73,6 +74,7 @@ func (h *S3Handler) initSettings(accessKey, secretKey string, proxyMode, authReq
|
|||||||
func (h *S3Handler) RegisterS3Routes(router *mux.Router) {
|
func (h *S3Handler) RegisterS3Routes(router *mux.Router) {
|
||||||
// 公共路由(不需要认证)
|
// 公共路由(不需要认证)
|
||||||
router.HandleFunc("/", h.handleListBuckets).Methods("GET")
|
router.HandleFunc("/", h.handleListBuckets).Methods("GET")
|
||||||
|
router.HandleFunc("/", h.handleOptions).Methods("OPTIONS")
|
||||||
|
|
||||||
// 带认证/虚拟主机的路由
|
// 带认证/虚拟主机的路由
|
||||||
protected := router.NewRoute().PathPrefix("/{bucket}").Subrouter()
|
protected := router.NewRoute().PathPrefix("/{bucket}").Subrouter()
|
||||||
@@ -80,7 +82,9 @@ func (h *S3Handler) RegisterS3Routes(router *mux.Router) {
|
|||||||
|
|
||||||
// Bucket operations
|
// Bucket operations
|
||||||
protected.HandleFunc("", h.handleBucketOperations).Methods("GET", "HEAD", "PUT", "DELETE")
|
protected.HandleFunc("", h.handleBucketOperations).Methods("GET", "HEAD", "PUT", "DELETE")
|
||||||
|
protected.HandleFunc("", h.handleOptions).Methods("OPTIONS")
|
||||||
protected.HandleFunc("/", h.handleBucketOperations).Methods("GET", "HEAD", "PUT", "DELETE")
|
protected.HandleFunc("/", h.handleBucketOperations).Methods("GET", "HEAD", "PUT", "DELETE")
|
||||||
|
protected.HandleFunc("/", h.handleOptions).Methods("OPTIONS")
|
||||||
|
|
||||||
// Multipart upload operations - must be registered before generic object operations
|
// Multipart upload operations - must be registered before generic object operations
|
||||||
protected.HandleFunc("/{key:.*}", h.handleUploadPart).Methods("PUT").Queries("partNumber", "{partNumber:[0-9]+}", "uploadId", "{uploadId}")
|
protected.HandleFunc("/{key:.*}", h.handleUploadPart).Methods("PUT").Queries("partNumber", "{partNumber:[0-9]+}", "uploadId", "{uploadId}")
|
||||||
@@ -92,6 +96,7 @@ func (h *S3Handler) RegisterS3Routes(router *mux.Router) {
|
|||||||
|
|
||||||
// Object operations - must be registered after multipart operations to avoid conflicts
|
// Object operations - must be registered after multipart operations to avoid conflicts
|
||||||
protected.HandleFunc("/{key:.*}", h.handleObjectOperations).Methods("GET", "HEAD", "PUT", "DELETE")
|
protected.HandleFunc("/{key:.*}", h.handleObjectOperations).Methods("GET", "HEAD", "PUT", "DELETE")
|
||||||
|
protected.HandleFunc("/{key:.*}", h.handleOptions).Methods("OPTIONS")
|
||||||
|
|
||||||
// 添加中间件
|
// 添加中间件
|
||||||
protected.Use(h.accessLogMiddleware)
|
protected.Use(h.accessLogMiddleware)
|
||||||
@@ -110,6 +115,10 @@ func (h *S3Handler) RegisterS3Routes(router *mux.Router) {
|
|||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *S3Handler) handleOptions(w http.ResponseWriter, _ *http.Request) {
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
}
|
||||||
|
|
||||||
func (h *S3Handler) loadSettings() handlerSettings {
|
func (h *S3Handler) loadSettings() handlerSettings {
|
||||||
if v := h.settings.Load(); v != nil {
|
if v := h.settings.Load(); v != nil {
|
||||||
return v.(handlerSettings)
|
return v.(handlerSettings)
|
||||||
|
|||||||
Reference in New Issue
Block a user