diff options
| author | Chris Lu <chris.lu@gmail.com> | 2018-09-19 22:01:41 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2018-09-19 22:01:41 -0700 |
| commit | f5471bcebf72e196040c61bf5f304beb5b7e2af0 (patch) | |
| tree | 13c11dd7e371a12ae71dfff3a0d9cde2d4e6fbbd | |
| parent | 25fb6f9a465d7371913c2898c6e3f701ed890b07 (diff) | |
| download | seaweedfs-f5471bcebf72e196040c61bf5f304beb5b7e2af0.tar.xz seaweedfs-f5471bcebf72e196040c61bf5f304beb5b7e2af0.zip | |
add bucket name in the redirection
| -rw-r--r-- | weed/s3api/s3api_object_handlers.go | 21 | ||||
| -rw-r--r-- | weed/s3api/s3api_server.go | 4 |
2 files changed, 17 insertions, 8 deletions
diff --git a/weed/s3api/s3api_object_handlers.go b/weed/s3api/s3api_object_handlers.go index 62017cb23..f459e17cf 100644 --- a/weed/s3api/s3api_object_handlers.go +++ b/weed/s3api/s3api_object_handlers.go @@ -61,13 +61,16 @@ func (s3a *S3ApiServer) PutObjectHandler(w http.ResponseWriter, r *http.Request) func (s3a *S3ApiServer) GetObjectHandler(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + bucket := vars["bucket"] + if strings.HasSuffix(r.URL.Path, "/") { writeErrorResponse(w, ErrNotImplemented, r.URL) return } - destUrl := fmt.Sprintf("http://%s%s%s", - s3a.option.Filer, s3a.option.BucketsPath, r.RequestURI) + destUrl := fmt.Sprintf("http://%s%s/%s%s", + s3a.option.Filer, s3a.option.BucketsPath, bucket, r.RequestURI) s3a.proxyToFiler(w, r, destUrl, passThroghResponse) @@ -75,8 +78,11 @@ func (s3a *S3ApiServer) GetObjectHandler(w http.ResponseWriter, r *http.Request) func (s3a *S3ApiServer) HeadObjectHandler(w http.ResponseWriter, r *http.Request) { - destUrl := fmt.Sprintf("http://%s%s%s", - s3a.option.Filer, s3a.option.BucketsPath, r.RequestURI) + vars := mux.Vars(r) + bucket := vars["bucket"] + + destUrl := fmt.Sprintf("http://%s%s/%s%s", + s3a.option.Filer, s3a.option.BucketsPath, bucket, r.RequestURI) s3a.proxyToFiler(w, r, destUrl, passThroghResponse) @@ -84,8 +90,11 @@ func (s3a *S3ApiServer) HeadObjectHandler(w http.ResponseWriter, r *http.Request func (s3a *S3ApiServer) DeleteObjectHandler(w http.ResponseWriter, r *http.Request) { - destUrl := fmt.Sprintf("http://%s%s%s", - s3a.option.Filer, s3a.option.BucketsPath, r.RequestURI) + vars := mux.Vars(r) + bucket := vars["bucket"] + + destUrl := fmt.Sprintf("http://%s%s/%s%s", + s3a.option.Filer, s3a.option.BucketsPath, bucket, r.RequestURI) s3a.proxyToFiler(w, r, destUrl, func(proxyResonse *http.Response, w http.ResponseWriter) { for k, v := range proxyResonse.Header { diff --git a/weed/s3api/s3api_server.go b/weed/s3api/s3api_server.go index 6722a519c..db798a546 100644 --- a/weed/s3api/s3api_server.go +++ b/weed/s3api/s3api_server.go @@ -71,10 +71,10 @@ func (s3a *S3ApiServer) registerRouter(router *mux.Router) { // DeleteBucket bucket.Methods("DELETE").HandlerFunc(s3a.DeleteBucketHandler) - // GetObject, but directory listing is not supported - bucket.Methods("GET").Path("/{object:.+}").HandlerFunc(s3a.GetObjectHandler) // ListObjectsV2 bucket.Methods("GET").HandlerFunc(s3a.ListObjectsV2Handler).Queries("list-type", "2") + // GetObject, but directory listing is not supported + bucket.Methods("GET").Path("/{object:.+}").HandlerFunc(s3a.GetObjectHandler) // ListObjectsV1 (Legacy) bucket.Methods("GET").HandlerFunc(s3a.ListObjectsV1Handler) |
