From 452f0f8335c36db681da7a37070ae8f49efaa441 Mon Sep 17 00:00:00 2001 From: "Frederick F. Kautz IV" Date: Sun, 29 Mar 2015 21:06:47 -0700 Subject: [PATCH] Cleaning up more api code --- pkg/api/api_object_handlers.go | 8 ++++---- pkg/api/headers.go | 14 ++++++-------- pkg/api/range.go | 2 +- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/pkg/api/api_object_handlers.go b/pkg/api/api_object_handlers.go index 5b6a0dd30..d4c53ae05 100644 --- a/pkg/api/api_object_handlers.go +++ b/pkg/api/api_object_handlers.go @@ -39,15 +39,15 @@ func (server *minioAPI) getObjectHandler(w http.ResponseWriter, req *http.Reques switch err := err.(type) { case nil: // success { - log.Println("Found: " + bucket + "#" + object) - httpRange, err := newRange(req, metadata.Size) + httpRange, err := getRequestedRange(req, metadata.Size) if err != nil { log.Error.Println(err) error := getErrorCode(InvalidRange) errorResponse := getErrorResponse(error, "/"+bucket+"/"+object) setCommonHeaders(w, getContentTypeString(acceptsContentType)) w.WriteHeader(error.HTTPStatusCode) - w.Write(encodeErrorResponse(errorResponse, acceptsContentType)) + encodedErrorResponse := encodeErrorResponse(errorResponse, acceptsContentType) + w.Write(encodedErrorResponse) return } switch httpRange.start == 0 && httpRange.length == 0 { @@ -60,7 +60,7 @@ func (server *minioAPI) getObjectHandler(w http.ResponseWriter, req *http.Reques } case false: metadata.Size = httpRange.length - writeRangeObjectHeaders(w, metadata, httpRange.getContentRange()) + setRangeObjectHeaders(w, metadata, httpRange) w.WriteHeader(http.StatusPartialContent) _, err := server.driver.GetPartialObject(w, bucket, object, httpRange.start, httpRange.length) if err != nil { diff --git a/pkg/api/headers.go b/pkg/api/headers.go index d938c6165..a6e103a79 100644 --- a/pkg/api/headers.go +++ b/pkg/api/headers.go @@ -65,18 +65,16 @@ func setObjectHeaders(w http.ResponseWriter, metadata drivers.ObjectMetadata) { w.Header().Set("ETag", metadata.Md5) w.Header().Set("Last-Modified", lastModified) w.Header().Set("Content-Length", strconv.FormatInt(metadata.Size, 10)) - w.Header().Set("Connection", "close") } // Write range object header -func writeRangeObjectHeaders(w http.ResponseWriter, metadata drivers.ObjectMetadata, ra string) { - lastModified := metadata.Created.Format(time.RFC1123) - // common headers +func setRangeObjectHeaders(w http.ResponseWriter, metadata drivers.ObjectMetadata, contentRange *httpRange) { + // set common headers setCommonHeaders(w, metadata.ContentType) - w.Header().Set("ETag", metadata.Md5) - w.Header().Set("Last-Modified", lastModified) - w.Header().Set("Content-Range", ra) - w.Header().Set("Content-Length", strconv.FormatInt(metadata.Size, 10)) + // set object headers + setObjectHeaders(w, metadata) + // set content range + w.Header().Set("Content-Range", contentRange.getContentRange()) } func encodeResponse(response interface{}, acceptsType contentType) []byte { diff --git a/pkg/api/range.go b/pkg/api/range.go index ae80dabcf..12f6788fc 100644 --- a/pkg/api/range.go +++ b/pkg/api/range.go @@ -40,7 +40,7 @@ func (r *httpRange) getContentRange() string { } // Grab new range from request header -func newRange(req *http.Request, size int64) (*httpRange, error) { +func getRequestedRange(req *http.Request, size int64) (*httpRange, error) { r := &httpRange{ start: 0, length: 0,