From d1d5f7a78db7b6f5e833ac59b889a19d15c2f6a1 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Wed, 29 Apr 2015 10:51:59 -0700 Subject: [PATCH] Collate success response into writeSuccessResponse(), add docs --- pkg/api/api_bucket_handlers.go | 12 +++--------- pkg/api/api_object_handlers.go | 9 ++++++--- pkg/api/api_response.go | 8 ++++++++ pkg/api/utils.go | 2 ++ 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/pkg/api/api_bucket_handlers.go b/pkg/api/api_bucket_handlers.go index 0cb2bbe3e..4ca78ad8f 100644 --- a/pkg/api/api_bucket_handlers.go +++ b/pkg/api/api_bucket_handlers.go @@ -172,9 +172,7 @@ func (server *minioAPI) putBucketHandler(w http.ResponseWriter, req *http.Reques switch iodine.ToError(err).(type) { case nil: { - w.Header().Set("Server", "Minio") - w.Header().Set("Connection", "close") - w.WriteHeader(http.StatusOK) + writeSuccessResponse(w) } case drivers.TooManyBuckets: { @@ -219,9 +217,7 @@ func (server *minioAPI) putBucketACLHandler(w http.ResponseWriter, req *http.Req switch iodine.ToError(err).(type) { case nil: { - w.Header().Set("Server", "Minio") - w.Header().Set("Connection", "close") - w.WriteHeader(http.StatusOK) + writeSuccessResponse(w) } case drivers.BucketNameInvalid: { @@ -258,7 +254,5 @@ func (server *minioAPI) headBucketHandler(w http.ResponseWriter, req *http.Reque } // Always a success if isValidOp succeeds - w.Header().Set("Server", "Minio") - w.Header().Set("Connection", "close") - w.WriteHeader(http.StatusOK) + writeSuccessResponse(w) } diff --git a/pkg/api/api_object_handlers.go b/pkg/api/api_object_handlers.go index fa13b4076..f23b20951 100644 --- a/pkg/api/api_object_handlers.go +++ b/pkg/api/api_object_handlers.go @@ -155,15 +155,18 @@ func (server *minioAPI) putObjectHandler(w http.ResponseWriter, req *http.Reques writeErrorResponse(w, req, InvalidDigest, acceptsContentType, req.URL.Path) return } + /// if Content-Length missing, incomplete request throw IncompleteBody size := req.Header.Get("Content-Length") if size == "" { writeErrorResponse(w, req, IncompleteBody, acceptsContentType, req.URL.Path) return } + /// maximum Upload size for objects in a single operation if isMaxObjectSize(size) { writeErrorResponse(w, req, EntityTooLarge, acceptsContentType, req.URL.Path) return } + /// minimum Upload size for objects in a single operation if isMinObjectSize(size) { writeErrorResponse(w, req, EntityTooSmall, acceptsContentType, req.URL.Path) return @@ -171,9 +174,9 @@ func (server *minioAPI) putObjectHandler(w http.ResponseWriter, req *http.Reques err := server.driver.CreateObject(bucket, object, "", md5, req.Body) switch err := iodine.ToError(err).(type) { case nil: - w.Header().Set("Server", "Minio") - w.Header().Set("Connection", "close") - w.WriteHeader(http.StatusOK) + { + writeSuccessResponse(w) + } case drivers.ObjectExists: { writeErrorResponse(w, req, MethodNotAllowed, acceptsContentType, req.URL.Path) diff --git a/pkg/api/api_response.go b/pkg/api/api_response.go index a7b2c9065..3692ba861 100644 --- a/pkg/api/api_response.go +++ b/pkg/api/api_response.go @@ -109,6 +109,14 @@ func generateObjectsListResult(bucket string, objects []drivers.ObjectMetadata, return data } +// writeSuccessResponse - write success headers +func writeSuccessResponse(w http.ResponseWriter) { + w.Header().Set("Server", "Minio") + w.Header().Set("Connection", "close") + w.WriteHeader(http.StatusOK) +} + +// writeErrorRespone - write error headers func writeErrorResponse(w http.ResponseWriter, req *http.Request, errorType int, acceptsContentType contentType, resource string) { error := getErrorCode(errorType) errorResponse := getErrorResponse(error, resource) diff --git a/pkg/api/utils.go b/pkg/api/utils.go index abc05c3e2..fda6b9b06 100644 --- a/pkg/api/utils.go +++ b/pkg/api/utils.go @@ -34,6 +34,8 @@ func isValidMD5(md5 string) bool { return true } +/// http://docs.aws.amazon.com/AmazonS3/latest/dev/UploadingObjects.html + // these should be configurable? const ( // maximum object size per PUT request is 5GB