diff --git a/cmd/api-response.go b/cmd/api-response.go index d89dafa5a..120132bb8 100644 --- a/cmd/api-response.go +++ b/cmd/api-response.go @@ -251,6 +251,14 @@ type DeleteObjectsResponse struct { Errors []DeleteError `xml:"Error,omitempty"` } +// PostResponse container for POST object request when success_action_status is set to 201 +type PostResponse struct { + Bucket string + Key string + ETag string + Location string +} + // getLocation get URL location. func getLocation(r *http.Request) string { return path.Clean(r.URL.Path) // Clean any trailing slashes. @@ -474,21 +482,24 @@ func generateMultiDeleteResponse(quiet bool, deletedObjects []ObjectIdentifier, return deleteResp } -// writeSuccessResponse write success headers and response if any. -func writeSuccessResponse(w http.ResponseWriter, response []byte) { +func writeResponse(w http.ResponseWriter, statusCode int, response []byte) { setCommonHeaders(w) + w.WriteHeader(statusCode) if response == nil { - w.WriteHeader(http.StatusOK) return } w.Write(response) w.(http.Flusher).Flush() } +// writeSuccessResponse write success headers and response if any. +func writeSuccessResponse(w http.ResponseWriter, response []byte) { + writeResponse(w, http.StatusOK, response) +} + // writeSuccessNoContent write success headers with http status 204 func writeSuccessNoContent(w http.ResponseWriter) { - setCommonHeaders(w) - w.WriteHeader(http.StatusNoContent) + writeResponse(w, http.StatusNoContent, nil) } // writeErrorRespone write error headers diff --git a/cmd/bucket-handlers.go b/cmd/bucket-handlers.go index afbc3dded..f8f6baacc 100644 --- a/cmd/bucket-handlers.go +++ b/cmd/bucket-handlers.go @@ -448,11 +448,22 @@ func (api objectAPIHandlers) PostPolicyBucketHandler(w http.ResponseWriter, r *h w.Header().Set("ETag", "\""+objInfo.MD5Sum+"\"") w.Header().Set("Location", getObjectLocation(bucket, object)) - // Set common headers. - setCommonHeaders(w) + // Decide what http response to send depending on success_action_status parameter + switch formValues[http.CanonicalHeaderKey("success_action_status")] { + case "201": + resp := encodeResponse(PostResponse{ + Bucket: bucket, + Key: object, + ETag: "\"" + objInfo.MD5Sum + "\"", + Location: getObjectLocation(bucket, object), + }) + writeResponse(w, http.StatusCreated, resp) - // Write successful response. - writeSuccessNoContent(w) + case "200": + writeSuccessResponse(w, nil) + default: + writeSuccessNoContent(w) + } // Notify object created event. eventNotify(eventData{