Merge pull request #109 from fkautz/pr_out_converting_unimplemented_methods_list_into_an_http_handler

master
Frederick F. Kautz IV 10 years ago
commit 39250b7c49
  1. 37
      pkg/webapi/minioapi/minioapi.go
  2. 9
      pkg/webapi/minioapi/minioapi_test.go

@ -61,15 +61,20 @@ func HttpHandler(storage mstorage.Storage) http.Handler {
mux.HandleFunc("/{bucket}/{object:.*}", api.headObjectHandler).Methods("HEAD") mux.HandleFunc("/{bucket}/{object:.*}", api.headObjectHandler).Methods("HEAD")
mux.HandleFunc("/{bucket}/{object:.*}", api.putObjectHandler).Methods("PUT") mux.HandleFunc("/{bucket}/{object:.*}", api.putObjectHandler).Methods("PUT")
return mux return ignoreUnimplementedBucketResources(mux)
} }
func (server *minioApi) listBucketsHandler(w http.ResponseWriter, req *http.Request) { func ignoreUnimplementedBucketResources(h http.Handler) http.Handler {
if server.ignoreUnImplementedBucketResources(req) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if ignoreUnImplementedObjectResources(r) {
w.WriteHeader(http.StatusNotImplemented) w.WriteHeader(http.StatusNotImplemented)
return } else {
h.ServeHTTP(w, r)
}
})
} }
func (server *minioApi) listBucketsHandler(w http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req) vars := mux.Vars(req)
prefix, ok := vars["prefix"] prefix, ok := vars["prefix"]
if !ok { if !ok {
@ -88,11 +93,6 @@ func (server *minioApi) listBucketsHandler(w http.ResponseWriter, req *http.Requ
} }
func (server *minioApi) listObjectsHandler(w http.ResponseWriter, req *http.Request) { func (server *minioApi) listObjectsHandler(w http.ResponseWriter, req *http.Request) {
if server.ignoreUnImplementedBucketResources(req) {
w.WriteHeader(http.StatusNotImplemented)
return
}
vars := mux.Vars(req) vars := mux.Vars(req)
bucket := vars["bucket"] bucket := vars["bucket"]
prefix, ok := vars["prefix"] prefix, ok := vars["prefix"]
@ -113,11 +113,6 @@ func (server *minioApi) listObjectsHandler(w http.ResponseWriter, req *http.Requ
} }
func (server *minioApi) putBucketHandler(w http.ResponseWriter, req *http.Request) { func (server *minioApi) putBucketHandler(w http.ResponseWriter, req *http.Request) {
if server.ignoreUnImplementedBucketResources(req) {
w.WriteHeader(http.StatusNotImplemented)
return
}
vars := mux.Vars(req) vars := mux.Vars(req)
bucket := vars["bucket"] bucket := vars["bucket"]
err := server.storage.StoreBucket(bucket) err := server.storage.StoreBucket(bucket)
@ -131,11 +126,6 @@ func (server *minioApi) putBucketHandler(w http.ResponseWriter, req *http.Reques
} }
func (server *minioApi) getObjectHandler(w http.ResponseWriter, req *http.Request) { func (server *minioApi) getObjectHandler(w http.ResponseWriter, req *http.Request) {
if server.ignoreUnImplementedObjectResources(req) {
w.WriteHeader(http.StatusNotImplemented)
return
}
vars := mux.Vars(req) vars := mux.Vars(req)
bucket := vars["bucket"] bucket := vars["bucket"]
object := vars["object"] object := vars["object"]
@ -182,11 +172,6 @@ func (server *minioApi) headObjectHandler(w http.ResponseWriter, req *http.Reque
} }
func (server *minioApi) putObjectHandler(w http.ResponseWriter, req *http.Request) { func (server *minioApi) putObjectHandler(w http.ResponseWriter, req *http.Request) {
if server.ignoreUnImplementedBucketResources(req) {
w.WriteHeader(http.StatusNotImplemented)
return
}
vars := mux.Vars(req) vars := mux.Vars(req)
bucket := vars["bucket"] bucket := vars["bucket"]
object := vars["object"] object := vars["object"]
@ -251,7 +236,7 @@ func generateBucketsListResult(buckets []mstorage.BucketMetadata) BucketListResp
//// helpers //// helpers
// Checks requests for unimplemented resources // Checks requests for unimplemented resources
func (server *minioApi) ignoreUnImplementedBucketResources(req *http.Request) bool { func ignoreUnImplementedBucketResources(req *http.Request) bool {
q := req.URL.Query() q := req.URL.Query()
for name := range q { for name := range q {
if unimplementedBucketResourceNames[name] { if unimplementedBucketResourceNames[name] {
@ -261,7 +246,7 @@ func (server *minioApi) ignoreUnImplementedBucketResources(req *http.Request) bo
return false return false
} }
func (server *minioApi) ignoreUnImplementedObjectResources(req *http.Request) bool { func ignoreUnImplementedObjectResources(req *http.Request) bool {
q := req.URL.Query() q := req.URL.Query()
for name := range q { for name := range q {
if unimplementedObjectResourceNames[name] { if unimplementedObjectResourceNames[name] {

@ -23,6 +23,7 @@ import (
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"sort"
"strconv" "strconv"
"testing" "testing"
"time" "time"
@ -322,8 +323,12 @@ func (s *MySuite) TestListBuckets(c *C) {
listResponse, err = readListBucket(response.Body) listResponse, err = readListBucket(response.Body)
c.Assert(err, IsNil) c.Assert(err, IsNil)
c.Assert(len(listResponse.Buckets.Bucket), Equals, 2) c.Assert(len(listResponse.Buckets.Bucket), Equals, 2)
c.Assert(listResponse.Buckets.Bucket[0].Name, Equals, "foo") var buckets []string
c.Assert(listResponse.Buckets.Bucket[1].Name, Equals, "bar") buckets = append(buckets, listResponse.Buckets.Bucket[0].Name)
buckets = append(buckets, listResponse.Buckets.Bucket[1].Name)
sort.Strings(buckets)
c.Assert(buckets[0], Equals, "bar")
c.Assert(buckets[1], Equals, "foo")
} }
func readListBucket(reader io.Reader) (BucketListResponse, error) { func readListBucket(reader io.Reader) (BucketListResponse, error) {

Loading…
Cancel
Save