PostForm: Follow success_action_status requirement (#3467)

S3 spec requires that Post Object response depends on the passed success_action_status. This commit implements that requirement.
master
Anis Elleuch 8 years ago committed by Harshavardhana
parent 1875a47495
commit 4692fdbb8f
  1. 21
      cmd/api-response.go
  2. 17
      cmd/bucket-handlers.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

@ -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.
case "200":
writeSuccessResponse(w, nil)
default:
writeSuccessNoContent(w)
}
// Notify object created event.
eventNotify(eventData{

Loading…
Cancel
Save