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

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

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

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

Loading…
Cancel
Save