From 7615a6bfe5cd18e861182a179bdd43621c1cbc6e Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Fri, 10 Jul 2015 21:06:43 -0700 Subject: [PATCH] HEAD shouldn't have any body, handle it in writeErrorResponse() --- Makefile | 2 +- pkg/server/api/bucket-handlers.go | 12 ++++-------- pkg/server/api/generic-handlers.go | 7 +------ pkg/server/api/object-handlers.go | 24 ++++++------------------ pkg/server/api/response.go | 7 +++++-- 5 files changed, 17 insertions(+), 35 deletions(-) diff --git a/Makefile b/Makefile index f435a8895..744dffc17 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ checkgopath: @for mcpath in $(echo ${GOPATH} | sed 's/:/\n/g' | grep -v Godeps); do if [ ! -d ${mcpath}/src/github.com/minio/minio ]; then echo "Project not found in ${mcpath}, please follow instructions provided at https://github.com/minio/minio/blob/master/CONTRIBUTING.md#setup-your-minio-github-repository" && exit 1; fi done getdeps: checkdeps checkgopath - @go get github.com/minio/godep && echo "Installed godep:" + @go get github.com/tools/godep && echo "Installed godep:" @go get github.com/golang/lint/golint && echo "Installed golint:" @go get golang.org/x/tools/cmd/vet && echo "Installed vet:" @go get github.com/fzipp/gocyclo && echo "Installed gocyclo:" diff --git a/pkg/server/api/bucket-handlers.go b/pkg/server/api/bucket-handlers.go index c3d21e13a..12b4d9527 100644 --- a/pkg/server/api/bucket-handlers.go +++ b/pkg/server/api/bucket-handlers.go @@ -405,17 +405,13 @@ func (api Minio) HeadBucketHandler(w http.ResponseWriter, req *http.Request) { case nil: writeSuccessResponse(w, acceptsContentType) case donut.SignatureDoesNotMatch: - error := getErrorCode(SignatureDoesNotMatch) - w.WriteHeader(error.HTTPStatusCode) + writeErrorResponse(w, req, SignatureDoesNotMatch, acceptsContentType, req.URL.Path) case donut.BucketNotFound: - error := getErrorCode(NoSuchBucket) - w.WriteHeader(error.HTTPStatusCode) + writeErrorResponse(w, req, NoSuchBucket, acceptsContentType, req.URL.Path) case donut.BucketNameInvalid: - error := getErrorCode(InvalidBucketName) - w.WriteHeader(error.HTTPStatusCode) + writeErrorResponse(w, req, InvalidBucketName, acceptsContentType, req.URL.Path) default: log.Error.Println(iodine.New(err, nil)) - error := getErrorCode(InternalError) - w.WriteHeader(error.HTTPStatusCode) + writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path) } } diff --git a/pkg/server/api/generic-handlers.go b/pkg/server/api/generic-handlers.go index 64578bc45..e3f81f19a 100644 --- a/pkg/server/api/generic-handlers.go +++ b/pkg/server/api/generic-handlers.go @@ -162,12 +162,7 @@ func IgnoreResourcesHandler(h http.Handler) http.Handler { func (h resourceHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { acceptsContentType := getContentType(r) if ignoreNotImplementedObjectResources(r) || ignoreNotImplementedBucketResources(r) { - error := getErrorCode(NotImplemented) - errorResponse := getErrorResponse(error, "") - encodeErrorResponse := encodeErrorResponse(errorResponse, acceptsContentType) - setCommonHeaders(w, getContentTypeString(acceptsContentType), len(encodeErrorResponse)) - w.WriteHeader(error.HTTPStatusCode) - w.Write(encodeErrorResponse) + writeErrorResponse(w, r, NotImplemented, acceptsContentType, r.URL.Path) return } h.handler.ServeHTTP(w, r) diff --git a/pkg/server/api/object-handlers.go b/pkg/server/api/object-handlers.go index 73231c681..5e9c3f2a7 100644 --- a/pkg/server/api/object-handlers.go +++ b/pkg/server/api/object-handlers.go @@ -147,30 +147,18 @@ func (api Minio) HeadObjectHandler(w http.ResponseWriter, req *http.Request) { setObjectHeaders(w, metadata) w.WriteHeader(http.StatusOK) case donut.SignatureDoesNotMatch: - error := getErrorCode(SignatureDoesNotMatch) - w.Header().Set("Server", "Minio") - w.WriteHeader(error.HTTPStatusCode) + writeErrorResponse(w, req, SignatureDoesNotMatch, acceptsContentType, req.URL.Path) case donut.BucketNameInvalid: - error := getErrorCode(InvalidBucketName) - w.Header().Set("Server", "Minio") - w.WriteHeader(error.HTTPStatusCode) + writeErrorResponse(w, req, InvalidBucketName, acceptsContentType, req.URL.Path) case donut.BucketNotFound: - error := getErrorCode(NoSuchBucket) - w.Header().Set("Server", "Minio") - w.WriteHeader(error.HTTPStatusCode) + writeErrorResponse(w, req, NoSuchBucket, acceptsContentType, req.URL.Path) case donut.ObjectNotFound: - error := getErrorCode(NoSuchKey) - w.Header().Set("Server", "Minio") - w.WriteHeader(error.HTTPStatusCode) + writeErrorResponse(w, req, NoSuchKey, acceptsContentType, req.URL.Path) case donut.ObjectNameInvalid: - error := getErrorCode(NoSuchKey) - w.Header().Set("Server", "Minio") - w.WriteHeader(error.HTTPStatusCode) + writeErrorResponse(w, req, NoSuchKey, acceptsContentType, req.URL.Path) default: log.Error.Println(iodine.New(err, nil)) - error := getErrorCode(InternalError) - w.Header().Set("Server", "Minio") - w.WriteHeader(error.HTTPStatusCode) + writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path) } } diff --git a/pkg/server/api/response.go b/pkg/server/api/response.go index 3c83e843e..dd3e35f1c 100644 --- a/pkg/server/api/response.go +++ b/pkg/server/api/response.go @@ -201,6 +201,9 @@ func writeErrorResponse(w http.ResponseWriter, req *http.Request, errorType int, setCommonHeaders(w, getContentTypeString(acceptsContentType), len(encodedErrorResponse)) // write Header w.WriteHeader(error.HTTPStatusCode) - // write error body - w.Write(encodedErrorResponse) + // HEAD should have no body + if req.Method != "HEAD" { + // write error body + w.Write(encodedErrorResponse) + } }