HEAD shouldn't have any body, handle it in writeErrorResponse()

This commit is contained in:
Harshavardhana 2015-07-10 21:06:43 -07:00
parent 7fde241ee2
commit 7615a6bfe5
5 changed files with 17 additions and 35 deletions

View File

@ -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:"

View File

@ -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)
}
}

View File

@ -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)

View File

@ -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)
}
}

View File

@ -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)
}
}