From 966cdd4f0549581a01a78a497ef053eecdf69b4d Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Wed, 11 Feb 2015 22:00:45 -0800 Subject: [PATCH] Reply in xml from validate and ignore handlers --- pkg/api/minioapi/errors.go | 8 ++++++-- pkg/api/minioapi/handler.go | 20 +++++++++++++++----- pkg/storage/inmemory/inmemory.go | 2 -- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/pkg/api/minioapi/errors.go b/pkg/api/minioapi/errors.go index cfc17f105..795692ed7 100644 --- a/pkg/api/minioapi/errors.go +++ b/pkg/api/minioapi/errors.go @@ -17,6 +17,7 @@ type ErrorResponse struct { Message string Resource string RequestId string + HostId string } /// Error codes, non exhaustive list @@ -162,9 +163,12 @@ func getErrorResponse(err Error, resource string) ErrorResponse { var data = ErrorResponse{} data.Code = err.Code data.Message = err.Description - data.Resource = resource + if resource != "" { + data.Resource = resource + } // TODO implement this in future - data.RequestId = "3LI37" + data.RequestId = "3L137" + data.HostId = "3L137" return data } diff --git a/pkg/api/minioapi/handler.go b/pkg/api/minioapi/handler.go index 623c70513..b0f04e8e5 100644 --- a/pkg/api/minioapi/handler.go +++ b/pkg/api/minioapi/handler.go @@ -32,17 +32,23 @@ func validateHandler(conf config.Config, h http.Handler) http.Handler { func (h vHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { accessKey := stripAccessKey(r) + acceptsContentType := getContentType(r) if accessKey != "" { if err := h.conf.ReadConfig(); err != nil { - w.WriteHeader(http.StatusInternalServerError) + error := errorCodeError(InternalError) + errorResponse := getErrorResponse(error, "") + w.WriteHeader(error.HttpStatusCode) + w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) } else { user := h.conf.GetKey(accessKey) - ok, err := signers.ValidateRequest(user, r) + ok, _ := signers.ValidateRequest(user, r) if ok { h.handler.ServeHTTP(w, r) } else { - w.WriteHeader(http.StatusUnauthorized) - w.Write([]byte(err.Error())) + error := errorCodeError(AccessDenied) + errorResponse := getErrorResponse(error, "") + w.WriteHeader(error.HttpStatusCode) + w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) } } } else { @@ -58,8 +64,12 @@ 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) { - w.WriteHeader(http.StatusNotImplemented) + error := errorCodeError(NotImplemented) + errorResponse := getErrorResponse(error, "") + w.WriteHeader(error.HttpStatusCode) + w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) } else { h.ServeHTTP(w, r) } diff --git a/pkg/storage/inmemory/inmemory.go b/pkg/storage/inmemory/inmemory.go index a1f63e058..b9b03e826 100644 --- a/pkg/storage/inmemory/inmemory.go +++ b/pkg/storage/inmemory/inmemory.go @@ -21,7 +21,6 @@ import ( "crypto/sha256" "fmt" "io" - "log" "sort" "strings" "time" @@ -52,7 +51,6 @@ func (storage *storage) CopyObjectToWriter(w io.Writer, bucket string, object st if val, ok := storage.objectdata[key]; ok { objectBuffer := bytes.NewBuffer(val.data) written, err := io.Copy(w, objectBuffer) - log.Println("I am here") return written, err } else { return 0, mstorage.ObjectNotFound{Bucket: bucket, Object: object}