Collate success response into writeSuccessResponse(), add docs

This commit is contained in:
Harshavardhana 2015-04-29 10:51:59 -07:00
parent 45a0fb21fa
commit d1d5f7a78d
4 changed files with 19 additions and 12 deletions

View file

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

View file

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

View file

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

View file

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