Send XML header before the first of whitespace chars (#2046)

* Sent XML header before the first of whitespace chars

XML parsing fails in aws cli due to unexpected whitespace character. To
fix this, we send the xml header before we send the first whitespace
character, if any.

* Fix race between sendWhiteSpaceChars and completeMultiUploadpart
This commit is contained in:
Krishnan Parthasarathi 2016-06-30 18:48:50 -07:00 committed by Harshavardhana
parent 285a94d2c0
commit bcb822c390
2 changed files with 18 additions and 4 deletions

View File

@ -502,10 +502,11 @@ func writeErrorResponse(w http.ResponseWriter, req *http.Request, errorCode APIE
setCommonHeaders(w)
// write Header
w.WriteHeader(error.HTTPStatusCode)
writeErrorResponseNoHeader(w, req, error, resource)
writeErrorResponseNoHeader(w, req, errorCode, resource)
}
func writeErrorResponseNoHeader(w http.ResponseWriter, req *http.Request, error APIError, resource string) {
func writeErrorResponseNoHeader(w http.ResponseWriter, req *http.Request, errorCode APIErrorCode, resource string) {
error := getAPIError(errorCode)
// Generate error response.
errorResponse := getAPIErrorResponse(error, resource)
encodedErrorResponse := encodeResponse(errorResponse)

View File

@ -974,6 +974,14 @@ func (api objectAPIHandlers) CompleteMultipartUploadHandler(w http.ResponseWrite
// Send 200 OK
setCommonHeaders(w)
w.WriteHeader(http.StatusOK)
// Xml headers need to be sent before we possibly send whitespace characters
// to the client.
_, err = w.Write([]byte(xml.Header))
if err != nil {
errorIf(err, "Unable to write XML header for complete multipart upload")
writeErrorResponseNoHeader(w, r, ErrInternalError, r.URL.Path)
return
}
doneCh := make(chan struct{})
// Signal that completeMultipartUpload is over via doneCh
@ -992,7 +1000,7 @@ func (api objectAPIHandlers) CompleteMultipartUploadHandler(w http.ResponseWrite
writePartSmallErrorResponse(w, r, oErr)
default:
// Handle all other generic issues.
writeErrorResponseNoHeader(w, r, getAPIError(toAPIErrorCode(err)), r.URL.Path)
writeErrorResponseNoHeader(w, r, toAPIErrorCode(err), r.URL.Path)
}
return
}
@ -1001,7 +1009,12 @@ func (api objectAPIHandlers) CompleteMultipartUploadHandler(w http.ResponseWrite
location := getLocation(r)
// Generate complete multipart response.
response := generateCompleteMultpartUploadResponse(bucket, object, location, md5Sum)
encodedSuccessResponse := encodeResponse(response)
encodedSuccessResponse, err := xml.Marshal(response)
if err != nil {
errorIf(err, "Unable to parse CompleteMultipartUpload response")
writeErrorResponseNoHeader(w, r, ErrInternalError, r.URL.Path)
return
}
// write success response.
w.Write(encodedSuccessResponse)
w.(http.Flusher).Flush()