Collate success response into writeSuccessResponse(), add docs

master
Harshavardhana 10 years ago
parent 45a0fb21fa
commit d1d5f7a78d
  1. 12
      pkg/api/api_bucket_handlers.go
  2. 9
      pkg/api/api_object_handlers.go
  3. 8
      pkg/api/api_response.go
  4. 2
      pkg/api/utils.go

@ -172,9 +172,7 @@ func (server *minioAPI) putBucketHandler(w http.ResponseWriter, req *http.Reques
switch iodine.ToError(err).(type) { switch iodine.ToError(err).(type) {
case nil: case nil:
{ {
w.Header().Set("Server", "Minio") writeSuccessResponse(w)
w.Header().Set("Connection", "close")
w.WriteHeader(http.StatusOK)
} }
case drivers.TooManyBuckets: case drivers.TooManyBuckets:
{ {
@ -219,9 +217,7 @@ func (server *minioAPI) putBucketACLHandler(w http.ResponseWriter, req *http.Req
switch iodine.ToError(err).(type) { switch iodine.ToError(err).(type) {
case nil: case nil:
{ {
w.Header().Set("Server", "Minio") writeSuccessResponse(w)
w.Header().Set("Connection", "close")
w.WriteHeader(http.StatusOK)
} }
case drivers.BucketNameInvalid: case drivers.BucketNameInvalid:
{ {
@ -258,7 +254,5 @@ func (server *minioAPI) headBucketHandler(w http.ResponseWriter, req *http.Reque
} }
// Always a success if isValidOp succeeds // Always a success if isValidOp succeeds
w.Header().Set("Server", "Minio") writeSuccessResponse(w)
w.Header().Set("Connection", "close")
w.WriteHeader(http.StatusOK)
} }

@ -155,15 +155,18 @@ func (server *minioAPI) putObjectHandler(w http.ResponseWriter, req *http.Reques
writeErrorResponse(w, req, InvalidDigest, acceptsContentType, req.URL.Path) writeErrorResponse(w, req, InvalidDigest, acceptsContentType, req.URL.Path)
return return
} }
/// if Content-Length missing, incomplete request throw IncompleteBody
size := req.Header.Get("Content-Length") size := req.Header.Get("Content-Length")
if size == "" { if size == "" {
writeErrorResponse(w, req, IncompleteBody, acceptsContentType, req.URL.Path) writeErrorResponse(w, req, IncompleteBody, acceptsContentType, req.URL.Path)
return return
} }
/// maximum Upload size for objects in a single operation
if isMaxObjectSize(size) { if isMaxObjectSize(size) {
writeErrorResponse(w, req, EntityTooLarge, acceptsContentType, req.URL.Path) writeErrorResponse(w, req, EntityTooLarge, acceptsContentType, req.URL.Path)
return return
} }
/// minimum Upload size for objects in a single operation
if isMinObjectSize(size) { if isMinObjectSize(size) {
writeErrorResponse(w, req, EntityTooSmall, acceptsContentType, req.URL.Path) writeErrorResponse(w, req, EntityTooSmall, acceptsContentType, req.URL.Path)
return return
@ -171,9 +174,9 @@ func (server *minioAPI) putObjectHandler(w http.ResponseWriter, req *http.Reques
err := server.driver.CreateObject(bucket, object, "", md5, req.Body) err := server.driver.CreateObject(bucket, object, "", md5, req.Body)
switch err := iodine.ToError(err).(type) { switch err := iodine.ToError(err).(type) {
case nil: case nil:
w.Header().Set("Server", "Minio") {
w.Header().Set("Connection", "close") writeSuccessResponse(w)
w.WriteHeader(http.StatusOK) }
case drivers.ObjectExists: case drivers.ObjectExists:
{ {
writeErrorResponse(w, req, MethodNotAllowed, acceptsContentType, req.URL.Path) writeErrorResponse(w, req, MethodNotAllowed, acceptsContentType, req.URL.Path)

@ -109,6 +109,14 @@ func generateObjectsListResult(bucket string, objects []drivers.ObjectMetadata,
return data 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) { func writeErrorResponse(w http.ResponseWriter, req *http.Request, errorType int, acceptsContentType contentType, resource string) {
error := getErrorCode(errorType) error := getErrorCode(errorType)
errorResponse := getErrorResponse(error, resource) errorResponse := getErrorResponse(error, resource)

@ -34,6 +34,8 @@ func isValidMD5(md5 string) bool {
return true return true
} }
/// http://docs.aws.amazon.com/AmazonS3/latest/dev/UploadingObjects.html
// these should be configurable? // these should be configurable?
const ( const (
// maximum object size per PUT request is 5GB // maximum object size per PUT request is 5GB

Loading…
Cancel
Save