From f7a06a5d1e5e4d49ada25ce1368f05c071e758a0 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Wed, 18 Feb 2015 12:15:33 -0800 Subject: [PATCH] Some more cleanup --- .../{minioapi_test.go => api_test.go} | 0 .../{buckets.go => bucket_handlers.go} | 0 .../minioapi/{errors.go => error_response.go} | 0 .../{validate.go => generic_handlers.go} | 30 +++++++++++-------- pkg/api/minioapi/{router.go => muxer.go} | 2 +- .../{objects.go => object_handlers.go} | 0 6 files changed, 19 insertions(+), 13 deletions(-) rename pkg/api/minioapi/{minioapi_test.go => api_test.go} (100%) rename pkg/api/minioapi/{buckets.go => bucket_handlers.go} (100%) rename pkg/api/minioapi/{errors.go => error_response.go} (100%) rename pkg/api/minioapi/{validate.go => generic_handlers.go} (83%) rename pkg/api/minioapi/{router.go => muxer.go} (96%) rename pkg/api/minioapi/{objects.go => object_handlers.go} (100%) diff --git a/pkg/api/minioapi/minioapi_test.go b/pkg/api/minioapi/api_test.go similarity index 100% rename from pkg/api/minioapi/minioapi_test.go rename to pkg/api/minioapi/api_test.go diff --git a/pkg/api/minioapi/buckets.go b/pkg/api/minioapi/bucket_handlers.go similarity index 100% rename from pkg/api/minioapi/buckets.go rename to pkg/api/minioapi/bucket_handlers.go diff --git a/pkg/api/minioapi/errors.go b/pkg/api/minioapi/error_response.go similarity index 100% rename from pkg/api/minioapi/errors.go rename to pkg/api/minioapi/error_response.go diff --git a/pkg/api/minioapi/validate.go b/pkg/api/minioapi/generic_handlers.go similarity index 83% rename from pkg/api/minioapi/validate.go rename to pkg/api/minioapi/generic_handlers.go index 5cc3f96e8..743496390 100644 --- a/pkg/api/minioapi/validate.go +++ b/pkg/api/minioapi/generic_handlers.go @@ -29,6 +29,10 @@ type vHandler struct { handler http.Handler } +type rHandler struct { + handler http.Handler +} + // grab AccessKey from authorization header func stripAccessKey(r *http.Request) string { fields := strings.Fields(r.Header.Get("Authorization")) @@ -78,18 +82,20 @@ func (h vHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } } -func ignoreUnimplementedResources(h http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - acceptsContentType := getContentType(r) - if ignoreUnImplementedObjectResources(r) || ignoreUnImplementedBucketResources(r) { - error := errorCodeError(NotImplemented) - errorResponse := getErrorResponse(error, "") - w.WriteHeader(error.HttpStatusCode) - w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) - } else { - h.ServeHTTP(w, r) - } - }) +func ignoreResourcesHandler(h http.Handler) http.Handler { + return rHandler{h} +} + +func (h rHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { + acceptsContentType := getContentType(r) + if ignoreUnImplementedObjectResources(r) || ignoreUnImplementedBucketResources(r) { + error := errorCodeError(NotImplemented) + errorResponse := getErrorResponse(error, "") + w.WriteHeader(error.HttpStatusCode) + w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) + } else { + h.handler.ServeHTTP(w, r) + } } //// helpers diff --git a/pkg/api/minioapi/router.go b/pkg/api/minioapi/muxer.go similarity index 96% rename from pkg/api/minioapi/router.go rename to pkg/api/minioapi/muxer.go index ac282dc49..a64645357 100644 --- a/pkg/api/minioapi/router.go +++ b/pkg/api/minioapi/muxer.go @@ -55,5 +55,5 @@ func HttpHandler(storage mstorage.Storage) http.Handler { mux.HandleFunc("/{bucket}/{object:.*}", api.headObjectHandler).Methods("HEAD") mux.HandleFunc("/{bucket}/{object:.*}", api.putObjectHandler).Methods("PUT") - return validateHandler(conf, ignoreUnimplementedResources(mux)) + return validateHandler(conf, ignoreResourcesHandler(mux)) } diff --git a/pkg/api/minioapi/objects.go b/pkg/api/minioapi/object_handlers.go similarity index 100% rename from pkg/api/minioapi/objects.go rename to pkg/api/minioapi/object_handlers.go