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

master
Harshavardhana 10 years ago
parent 7fde241ee2
commit 7615a6bfe5
  1. 2
      Makefile
  2. 12
      pkg/server/api/bucket-handlers.go
  3. 7
      pkg/server/api/generic-handlers.go
  4. 24
      pkg/server/api/object-handlers.go
  5. 7
      pkg/server/api/response.go

@ -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 @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 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 github.com/golang/lint/golint && echo "Installed golint:"
@go get golang.org/x/tools/cmd/vet && echo "Installed vet:" @go get golang.org/x/tools/cmd/vet && echo "Installed vet:"
@go get github.com/fzipp/gocyclo && echo "Installed gocyclo:" @go get github.com/fzipp/gocyclo && echo "Installed gocyclo:"

@ -405,17 +405,13 @@ func (api Minio) HeadBucketHandler(w http.ResponseWriter, req *http.Request) {
case nil: case nil:
writeSuccessResponse(w, acceptsContentType) writeSuccessResponse(w, acceptsContentType)
case donut.SignatureDoesNotMatch: case donut.SignatureDoesNotMatch:
error := getErrorCode(SignatureDoesNotMatch) writeErrorResponse(w, req, SignatureDoesNotMatch, acceptsContentType, req.URL.Path)
w.WriteHeader(error.HTTPStatusCode)
case donut.BucketNotFound: case donut.BucketNotFound:
error := getErrorCode(NoSuchBucket) writeErrorResponse(w, req, NoSuchBucket, acceptsContentType, req.URL.Path)
w.WriteHeader(error.HTTPStatusCode)
case donut.BucketNameInvalid: case donut.BucketNameInvalid:
error := getErrorCode(InvalidBucketName) writeErrorResponse(w, req, InvalidBucketName, acceptsContentType, req.URL.Path)
w.WriteHeader(error.HTTPStatusCode)
default: default:
log.Error.Println(iodine.New(err, nil)) log.Error.Println(iodine.New(err, nil))
error := getErrorCode(InternalError) writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
w.WriteHeader(error.HTTPStatusCode)
} }
} }

@ -162,12 +162,7 @@ func IgnoreResourcesHandler(h http.Handler) http.Handler {
func (h resourceHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (h resourceHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
acceptsContentType := getContentType(r) acceptsContentType := getContentType(r)
if ignoreNotImplementedObjectResources(r) || ignoreNotImplementedBucketResources(r) { if ignoreNotImplementedObjectResources(r) || ignoreNotImplementedBucketResources(r) {
error := getErrorCode(NotImplemented) writeErrorResponse(w, r, NotImplemented, acceptsContentType, r.URL.Path)
errorResponse := getErrorResponse(error, "")
encodeErrorResponse := encodeErrorResponse(errorResponse, acceptsContentType)
setCommonHeaders(w, getContentTypeString(acceptsContentType), len(encodeErrorResponse))
w.WriteHeader(error.HTTPStatusCode)
w.Write(encodeErrorResponse)
return return
} }
h.handler.ServeHTTP(w, r) h.handler.ServeHTTP(w, r)

@ -147,30 +147,18 @@ func (api Minio) HeadObjectHandler(w http.ResponseWriter, req *http.Request) {
setObjectHeaders(w, metadata) setObjectHeaders(w, metadata)
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
case donut.SignatureDoesNotMatch: case donut.SignatureDoesNotMatch:
error := getErrorCode(SignatureDoesNotMatch) writeErrorResponse(w, req, SignatureDoesNotMatch, acceptsContentType, req.URL.Path)
w.Header().Set("Server", "Minio")
w.WriteHeader(error.HTTPStatusCode)
case donut.BucketNameInvalid: case donut.BucketNameInvalid:
error := getErrorCode(InvalidBucketName) writeErrorResponse(w, req, InvalidBucketName, acceptsContentType, req.URL.Path)
w.Header().Set("Server", "Minio")
w.WriteHeader(error.HTTPStatusCode)
case donut.BucketNotFound: case donut.BucketNotFound:
error := getErrorCode(NoSuchBucket) writeErrorResponse(w, req, NoSuchBucket, acceptsContentType, req.URL.Path)
w.Header().Set("Server", "Minio")
w.WriteHeader(error.HTTPStatusCode)
case donut.ObjectNotFound: case donut.ObjectNotFound:
error := getErrorCode(NoSuchKey) writeErrorResponse(w, req, NoSuchKey, acceptsContentType, req.URL.Path)
w.Header().Set("Server", "Minio")
w.WriteHeader(error.HTTPStatusCode)
case donut.ObjectNameInvalid: case donut.ObjectNameInvalid:
error := getErrorCode(NoSuchKey) writeErrorResponse(w, req, NoSuchKey, acceptsContentType, req.URL.Path)
w.Header().Set("Server", "Minio")
w.WriteHeader(error.HTTPStatusCode)
default: default:
log.Error.Println(iodine.New(err, nil)) log.Error.Println(iodine.New(err, nil))
error := getErrorCode(InternalError) writeErrorResponse(w, req, InternalError, acceptsContentType, req.URL.Path)
w.Header().Set("Server", "Minio")
w.WriteHeader(error.HTTPStatusCode)
} }
} }

@ -201,6 +201,9 @@ func writeErrorResponse(w http.ResponseWriter, req *http.Request, errorType int,
setCommonHeaders(w, getContentTypeString(acceptsContentType), len(encodedErrorResponse)) setCommonHeaders(w, getContentTypeString(acceptsContentType), len(encodedErrorResponse))
// write Header // write Header
w.WriteHeader(error.HTTPStatusCode) w.WriteHeader(error.HTTPStatusCode)
// write error body // HEAD should have no body
w.Write(encodedErrorResponse) if req.Method != "HEAD" {
// write error body
w.Write(encodedErrorResponse)
}
} }

Loading…
Cancel
Save