mirror of
https://github.com/minio/minio.git
synced 2024-12-24 22:25:54 -05:00
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.
This commit is contained in:
parent
1875a47495
commit
4692fdbb8f
@ -251,6 +251,14 @@ type DeleteObjectsResponse struct {
|
|||||||
Errors []DeleteError `xml:"Error,omitempty"`
|
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.
|
// getLocation get URL location.
|
||||||
func getLocation(r *http.Request) string {
|
func getLocation(r *http.Request) string {
|
||||||
return path.Clean(r.URL.Path) // Clean any trailing slashes.
|
return path.Clean(r.URL.Path) // Clean any trailing slashes.
|
||||||
@ -474,21 +482,24 @@ func generateMultiDeleteResponse(quiet bool, deletedObjects []ObjectIdentifier,
|
|||||||
return deleteResp
|
return deleteResp
|
||||||
}
|
}
|
||||||
|
|
||||||
// writeSuccessResponse write success headers and response if any.
|
func writeResponse(w http.ResponseWriter, statusCode int, response []byte) {
|
||||||
func writeSuccessResponse(w http.ResponseWriter, response []byte) {
|
|
||||||
setCommonHeaders(w)
|
setCommonHeaders(w)
|
||||||
|
w.WriteHeader(statusCode)
|
||||||
if response == nil {
|
if response == nil {
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.Write(response)
|
w.Write(response)
|
||||||
w.(http.Flusher).Flush()
|
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
|
// writeSuccessNoContent write success headers with http status 204
|
||||||
func writeSuccessNoContent(w http.ResponseWriter) {
|
func writeSuccessNoContent(w http.ResponseWriter) {
|
||||||
setCommonHeaders(w)
|
writeResponse(w, http.StatusNoContent, nil)
|
||||||
w.WriteHeader(http.StatusNoContent)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// writeErrorRespone write error headers
|
// 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("ETag", "\""+objInfo.MD5Sum+"\"")
|
||||||
w.Header().Set("Location", getObjectLocation(bucket, object))
|
w.Header().Set("Location", getObjectLocation(bucket, object))
|
||||||
|
|
||||||
// Set common headers.
|
// Decide what http response to send depending on success_action_status parameter
|
||||||
setCommonHeaders(w)
|
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":
|
||||||
writeSuccessNoContent(w)
|
writeSuccessResponse(w, nil)
|
||||||
|
default:
|
||||||
|
writeSuccessNoContent(w)
|
||||||
|
}
|
||||||
|
|
||||||
// Notify object created event.
|
// Notify object created event.
|
||||||
eventNotify(eventData{
|
eventNotify(eventData{
|
||||||
|
Loading…
Reference in New Issue
Block a user