From d64423305486caa5e8e039a2dbbf1a8fd10ff6a8 Mon Sep 17 00:00:00 2001 From: "Frederick F. Kautz IV" Date: Sun, 29 Mar 2015 18:48:51 -0700 Subject: [PATCH] Rename writeObjectHeaders to setObjectHeaders, fix writing multiple headers bug --- pkg/api/api_object_handlers.go | 16 ++++------------ pkg/api/headers.go | 2 +- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/pkg/api/api_object_handlers.go b/pkg/api/api_object_handlers.go index ead70cd5c..5b6a0dd30 100644 --- a/pkg/api/api_object_handlers.go +++ b/pkg/api/api_object_handlers.go @@ -52,14 +52,10 @@ func (server *minioAPI) getObjectHandler(w http.ResponseWriter, req *http.Reques } switch httpRange.start == 0 && httpRange.length == 0 { case true: - writeObjectHeaders(w, metadata) + setObjectHeaders(w, metadata) if _, err := server.driver.GetObject(w, bucket, object); err != nil { log.Error.Println(err) - error := getErrorCode(InternalError) - errorResponse := getErrorResponse(error, "/"+bucket+"/"+object) - setCommonHeaders(w, getContentTypeString(acceptsContentType)) - w.WriteHeader(error.HTTPStatusCode) - w.Write(encodeErrorResponse(errorResponse, acceptsContentType)) + // unable to write headers, we've already printed data. Just close the connection. return } case false: @@ -69,11 +65,7 @@ func (server *minioAPI) getObjectHandler(w http.ResponseWriter, req *http.Reques _, err := server.driver.GetPartialObject(w, bucket, object, httpRange.start, httpRange.length) if err != nil { log.Error.Println(err) - error := getErrorCode(InternalError) - errorResponse := getErrorResponse(error, "/"+bucket+"/"+object) - setCommonHeaders(w, getContentTypeString(acceptsContentType)) - w.WriteHeader(error.HTTPStatusCode) - w.Write(encodeErrorResponse(errorResponse, acceptsContentType)) + // unable to write headers, we've already printed data. Just close the connection. return } @@ -137,7 +129,7 @@ func (server *minioAPI) headObjectHandler(w http.ResponseWriter, req *http.Reque metadata, err := server.driver.GetObjectMetadata(bucket, object, "") switch err := err.(type) { case nil: - writeObjectHeaders(w, metadata) + setObjectHeaders(w, metadata) case drivers.ObjectNotFound: { error := getErrorCode(NoSuchKey) diff --git a/pkg/api/headers.go b/pkg/api/headers.go index c064541cb..d938c6165 100644 --- a/pkg/api/headers.go +++ b/pkg/api/headers.go @@ -58,7 +58,7 @@ func encodeErrorResponse(response interface{}, acceptsType contentType) []byte { } // Write object header -func writeObjectHeaders(w http.ResponseWriter, metadata drivers.ObjectMetadata) { +func setObjectHeaders(w http.ResponseWriter, metadata drivers.ObjectMetadata) { lastModified := metadata.Created.Format(time.RFC1123) // common headers setCommonHeaders(w, metadata.ContentType)