Fix: permit trailing slash for compatible with S3.

ex.
s3cmd requests to path:`/<bucket>/` for PutBucket.
master
Kanai Masumi 9 years ago
parent f00f674b69
commit 84de2e33c4
  1. 40
      routers.go
  2. 9
      server_fs_test.go

@ -32,25 +32,29 @@ type CloudStorageAPI struct {
// registerCloudStorageAPI - register all the handlers to their respective paths // registerCloudStorageAPI - register all the handlers to their respective paths
func registerCloudStorageAPI(mux *router.Router, a CloudStorageAPI) { func registerCloudStorageAPI(mux *router.Router, a CloudStorageAPI) {
mux.HandleFunc("/", a.ListBucketsHandler).Methods("GET") root := mux.NewRoute().PathPrefix("/").Subrouter()
mux.HandleFunc("/{bucket}", a.GetBucketACLHandler).Queries("acl", "").Methods("GET") bucket := root.PathPrefix("/{bucket}").Subrouter()
mux.HandleFunc("/{bucket}", a.ListMultipartUploadsHandler).Queries("uploads", "").Methods("GET")
mux.HandleFunc("/{bucket}", a.ListObjectsHandler).Methods("GET")
mux.HandleFunc("/{bucket}", a.PutBucketACLHandler).Queries("acl", "").Methods("PUT")
mux.HandleFunc("/{bucket}", a.PutBucketHandler).Methods("PUT")
mux.HandleFunc("/{bucket}", a.HeadBucketHandler).Methods("HEAD")
mux.HandleFunc("/{bucket}", a.PostPolicyBucketHandler).Methods("POST")
mux.HandleFunc("/{bucket}/{object:.*}", a.HeadObjectHandler).Methods("HEAD")
mux.HandleFunc("/{bucket}/{object:.*}", a.PutObjectPartHandler).Queries("partNumber", "{partNumber:[0-9]+}", "uploadId", "{uploadId:.*}").Methods("PUT")
mux.HandleFunc("/{bucket}/{object:.*}", a.ListObjectPartsHandler).Queries("uploadId", "{uploadId:.*}").Methods("GET")
mux.HandleFunc("/{bucket}/{object:.*}", a.CompleteMultipartUploadHandler).Queries("uploadId", "{uploadId:.*}").Methods("POST")
mux.HandleFunc("/{bucket}/{object:.*}", a.NewMultipartUploadHandler).Queries("uploads", "").Methods("POST")
mux.HandleFunc("/{bucket}/{object:.*}", a.AbortMultipartUploadHandler).Queries("uploadId", "{uploadId:.*}").Methods("DELETE")
mux.HandleFunc("/{bucket}/{object:.*}", a.GetObjectHandler).Methods("GET")
mux.HandleFunc("/{bucket}/{object:.*}", a.PutObjectHandler).Methods("PUT")
mux.HandleFunc("/{bucket}", a.DeleteBucketHandler).Methods("DELETE") bucket.Methods("HEAD").Path("/{object:.+}").HandlerFunc(a.HeadObjectHandler)
mux.HandleFunc("/{bucket}/{object:.*}", a.DeleteObjectHandler).Methods("DELETE") bucket.Methods("PUT").Path("/{object:.+}").HandlerFunc(a.PutObjectPartHandler).Queries("partNumber", "{partNumber:[0-9]+}", "uploadId", "{uploadId:.*}")
bucket.Methods("GET").Path("/{object:.+}").HandlerFunc(a.ListObjectPartsHandler).Queries("uploadId", "{uploadId:.*}")
bucket.Methods("POST").Path("/{object:.+}").HandlerFunc(a.CompleteMultipartUploadHandler).Queries("uploadId", "{uploadId:.*}")
bucket.Methods("POST").Path("/{object:.+}").HandlerFunc(a.NewMultipartUploadHandler).Queries("uploads", "")
bucket.Methods("DELETE").Path("/{object:.+}").HandlerFunc(a.AbortMultipartUploadHandler).Queries("uploadId", "{uploadId:.*}")
bucket.Methods("GET").Path("/{object:.+}").HandlerFunc(a.GetObjectHandler)
bucket.Methods("PUT").Path("/{object:.+}").HandlerFunc(a.PutObjectHandler)
bucket.Methods("DELETE").Path("/{object:.+}").HandlerFunc(a.DeleteObjectHandler)
bucket.Methods("GET").HandlerFunc(a.GetBucketACLHandler).Queries("acl", "")
bucket.Methods("GET").HandlerFunc(a.ListMultipartUploadsHandler).Queries("uploads", "")
bucket.Methods("GET").HandlerFunc(a.ListObjectsHandler)
bucket.Methods("PUT").HandlerFunc(a.PutBucketACLHandler).Queries("acl", "")
bucket.Methods("PUT").HandlerFunc(a.PutBucketHandler)
bucket.Methods("HEAD").HandlerFunc(a.HeadBucketHandler)
bucket.Methods("POST").HandlerFunc(a.PostPolicyBucketHandler)
bucket.Methods("DELETE").HandlerFunc(a.DeleteBucketHandler)
root.Methods("GET").HandlerFunc(a.ListBucketsHandler)
} }
// getNewCloudStorageAPI instantiate a new CloudStorageAPI // getNewCloudStorageAPI instantiate a new CloudStorageAPI

@ -524,6 +524,15 @@ func (s *MyAPIFSCacheSuite) TestPutBucket(c *C) {
response, err := client.Do(request) response, err := client.Do(request)
c.Assert(err, IsNil) c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK) c.Assert(response.StatusCode, Equals, http.StatusOK)
request, err = s.newRequest("PUT", testAPIFSCacheServer.URL+"/put-bucket-slash/", 0, nil)
c.Assert(err, IsNil)
request.Header.Add("x-amz-acl", "private")
client = http.Client{}
response, err = client.Do(request)
c.Assert(err, IsNil)
c.Assert(response.StatusCode, Equals, http.StatusOK)
} }
func (s *MyAPIFSCacheSuite) TestPutObject(c *C) { func (s *MyAPIFSCacheSuite) TestPutObject(c *C) {

Loading…
Cancel
Save