Merge pull request #176 from harshavardhana/pr_out_some_more_cleanup

This commit is contained in:
Harshavardhana 2015-02-18 12:16:34 -08:00
commit 2bc7ded828
6 changed files with 19 additions and 13 deletions

View File

@ -29,6 +29,10 @@ type vHandler struct {
handler http.Handler handler http.Handler
} }
type rHandler struct {
handler http.Handler
}
// grab AccessKey from authorization header // grab AccessKey from authorization header
func stripAccessKey(r *http.Request) string { func stripAccessKey(r *http.Request) string {
fields := strings.Fields(r.Header.Get("Authorization")) 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 { func ignoreResourcesHandler(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return rHandler{h}
acceptsContentType := getContentType(r) }
if ignoreUnImplementedObjectResources(r) || ignoreUnImplementedBucketResources(r) {
error := errorCodeError(NotImplemented) func (h rHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
errorResponse := getErrorResponse(error, "") acceptsContentType := getContentType(r)
w.WriteHeader(error.HttpStatusCode) if ignoreUnImplementedObjectResources(r) || ignoreUnImplementedBucketResources(r) {
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) error := errorCodeError(NotImplemented)
} else { errorResponse := getErrorResponse(error, "")
h.ServeHTTP(w, r) w.WriteHeader(error.HttpStatusCode)
} w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
}) } else {
h.handler.ServeHTTP(w, r)
}
} }
//// helpers //// helpers

View File

@ -55,5 +55,5 @@ 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 validateHandler(conf, ignoreUnimplementedResources(mux)) return validateHandler(conf, ignoreResourcesHandler(mux))
} }