object layer: Send 200 OK and whitespace chars (#1897)

master
Krishnan Parthasarathi 9 years ago committed by Harshavardhana
parent e2743d05e8
commit 129ebbd685
  1. 10
      api-response.go
  2. 33
      object-handlers.go

@ -497,13 +497,17 @@ func writeSuccessNoContent(w http.ResponseWriter) {
// writeErrorRespone write error headers // writeErrorRespone write error headers
func writeErrorResponse(w http.ResponseWriter, req *http.Request, errorCode APIErrorCode, resource string) { func writeErrorResponse(w http.ResponseWriter, req *http.Request, errorCode APIErrorCode, resource string) {
error := getAPIError(errorCode) error := getAPIError(errorCode)
// generate error response
errorResponse := getAPIErrorResponse(error, resource)
encodedErrorResponse := encodeResponse(errorResponse)
// set common headers // set common headers
setCommonHeaders(w) setCommonHeaders(w)
// write Header // write Header
w.WriteHeader(error.HTTPStatusCode) w.WriteHeader(error.HTTPStatusCode)
writeErrorResponseNoHeader(w, req, error, resource)
}
func writeErrorResponseNoHeader(w http.ResponseWriter, req *http.Request, error APIError, resource string) {
// generate error response
errorResponse := getAPIErrorResponse(error, resource)
encodedErrorResponse := encodeResponse(errorResponse)
// HEAD should have no body, do not attempt to write to it // HEAD should have no body, do not attempt to write to it
if req.Method != "HEAD" { if req.Method != "HEAD" {
// write error body // write error body

@ -843,6 +843,19 @@ func (api objectAPIHandlers) AbortMultipartUploadHandler(w http.ResponseWriter,
writeSuccessNoContent(w) writeSuccessNoContent(w)
} }
// Send whitespace character, once every 5secs, until CompleteMultipartUpload is done.
// CompleteMultipartUpload method of the object layer indicates that it's done via doneCh
func sendWhiteSpaceChars(w http.ResponseWriter, doneCh <-chan struct{}) {
for {
select {
case <-time.After(5 * time.Second):
w.Write([]byte(" "))
case <-doneCh:
return
}
}
}
// ListObjectPartsHandler - List object parts // ListObjectPartsHandler - List object parts
func (api objectAPIHandlers) ListObjectPartsHandler(w http.ResponseWriter, r *http.Request) { func (api objectAPIHandlers) ListObjectPartsHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r) vars := mux.Vars(r)
@ -946,21 +959,33 @@ func (api objectAPIHandlers) CompleteMultipartUploadHandler(w http.ResponseWrite
completeParts = append(completeParts, part) completeParts = append(completeParts, part)
} }
// Complete multipart upload. // Complete multipart upload.
// Send 200 OK
setCommonHeaders(w)
w.WriteHeader(http.StatusOK)
doneCh := make(chan struct{})
// Signal that completeMultipartUpload is over via doneCh
go func(doneCh chan<- struct{}) {
md5Sum, err = api.ObjectAPI.CompleteMultipartUpload(bucket, object, uploadID, completeParts) md5Sum, err = api.ObjectAPI.CompleteMultipartUpload(bucket, object, uploadID, completeParts)
doneCh <- struct{}{}
}(doneCh)
sendWhiteSpaceChars(w, doneCh)
if err != nil { if err != nil {
errorIf(err, "Unable to complete multipart upload.") errorIf(err, "Unable to complete multipart upload.")
writeErrorResponse(w, r, toAPIErrorCode(err), r.URL.Path) writeErrorResponseNoHeader(w, r, getAPIError(toAPIErrorCode(err)), r.URL.Path)
return return
} }
// Get object location. // Get object location.
location := getLocation(r) location := getLocation(r)
// Generate complete multipart response. // Generate complete multipart response.
response := generateCompleteMultpartUploadResponse(bucket, object, location, md5Sum) response := generateCompleteMultpartUploadResponse(bucket, object, location, md5Sum)
encodedSuccessResponse := encodeResponse(response) encodedSuccessResponse := encodeResponse(response)
// Write headers.
setCommonHeaders(w)
// write success response. // write success response.
writeSuccessResponse(w, encodedSuccessResponse) w.Write(encodedSuccessResponse)
w.(http.Flusher).Flush()
} }
/// Delete objectAPIHandlers /// Delete objectAPIHandlers

Loading…
Cancel
Save