mirror of
https://github.com/minio/minio.git
synced 2025-01-12 15:33:22 -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) {
|
switch err := err.(type) {
|
||||||
case nil: // success
|
case nil: // success
|
||||||
{
|
{
|
||||||
log.Println("Found: " + bucket + "#" + object)
|
httpRange, err := getRequestedRange(req, metadata.Size)
|
||||||
httpRange, err := newRange(req, metadata.Size)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error.Println(err)
|
log.Error.Println(err)
|
||||||
error := getErrorCode(InvalidRange)
|
error := getErrorCode(InvalidRange)
|
||||||
errorResponse := getErrorResponse(error, "/"+bucket+"/"+object)
|
errorResponse := getErrorResponse(error, "/"+bucket+"/"+object)
|
||||||
setCommonHeaders(w, getContentTypeString(acceptsContentType))
|
setCommonHeaders(w, getContentTypeString(acceptsContentType))
|
||||||
w.WriteHeader(error.HTTPStatusCode)
|
w.WriteHeader(error.HTTPStatusCode)
|
||||||
w.Write(encodeErrorResponse(errorResponse, acceptsContentType))
|
encodedErrorResponse := encodeErrorResponse(errorResponse, acceptsContentType)
|
||||||
|
w.Write(encodedErrorResponse)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
switch httpRange.start == 0 && httpRange.length == 0 {
|
switch httpRange.start == 0 && httpRange.length == 0 {
|
||||||
@ -60,7 +60,7 @@ func (server *minioAPI) getObjectHandler(w http.ResponseWriter, req *http.Reques
|
|||||||
}
|
}
|
||||||
case false:
|
case false:
|
||||||
metadata.Size = httpRange.length
|
metadata.Size = httpRange.length
|
||||||
writeRangeObjectHeaders(w, metadata, httpRange.getContentRange())
|
setRangeObjectHeaders(w, metadata, httpRange)
|
||||||
w.WriteHeader(http.StatusPartialContent)
|
w.WriteHeader(http.StatusPartialContent)
|
||||||
_, err := server.driver.GetPartialObject(w, bucket, object, httpRange.start, httpRange.length)
|
_, err := server.driver.GetPartialObject(w, bucket, object, httpRange.start, httpRange.length)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -65,18 +65,16 @@ func setObjectHeaders(w http.ResponseWriter, metadata drivers.ObjectMetadata) {
|
|||||||
w.Header().Set("ETag", metadata.Md5)
|
w.Header().Set("ETag", metadata.Md5)
|
||||||
w.Header().Set("Last-Modified", lastModified)
|
w.Header().Set("Last-Modified", lastModified)
|
||||||
w.Header().Set("Content-Length", strconv.FormatInt(metadata.Size, 10))
|
w.Header().Set("Content-Length", strconv.FormatInt(metadata.Size, 10))
|
||||||
w.Header().Set("Connection", "close")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write range object header
|
// Write range object header
|
||||||
func writeRangeObjectHeaders(w http.ResponseWriter, metadata drivers.ObjectMetadata, ra string) {
|
func setRangeObjectHeaders(w http.ResponseWriter, metadata drivers.ObjectMetadata, contentRange *httpRange) {
|
||||||
lastModified := metadata.Created.Format(time.RFC1123)
|
// set common headers
|
||||||
// common headers
|
|
||||||
setCommonHeaders(w, metadata.ContentType)
|
setCommonHeaders(w, metadata.ContentType)
|
||||||
w.Header().Set("ETag", metadata.Md5)
|
// set object headers
|
||||||
w.Header().Set("Last-Modified", lastModified)
|
setObjectHeaders(w, metadata)
|
||||||
w.Header().Set("Content-Range", ra)
|
// set content range
|
||||||
w.Header().Set("Content-Length", strconv.FormatInt(metadata.Size, 10))
|
w.Header().Set("Content-Range", contentRange.getContentRange())
|
||||||
}
|
}
|
||||||
|
|
||||||
func encodeResponse(response interface{}, acceptsType contentType) []byte {
|
func encodeResponse(response interface{}, acceptsType contentType) []byte {
|
||||||
|
@ -40,7 +40,7 @@ func (r *httpRange) getContentRange() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Grab new range from request header
|
// 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{
|
r := &httpRange{
|
||||||
start: 0,
|
start: 0,
|
||||||
length: 0,
|
length: 0,
|
||||||
|
Loading…
Reference in New Issue
Block a user