mirror of
https://github.com/minio/minio.git
synced 2024-12-24 22:25:54 -05:00
Cleaning up more api code
This commit is contained in:
parent
0f6abe9ee3
commit
452f0f8335
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user