mirror of https://github.com/minio/minio.git
Adding HEAD verb to minioapi
This commit is contained in:
parent
3a3d9989d1
commit
8d1c447aac
|
@ -115,8 +115,12 @@ func start(ctrlChannel <-chan string, errorChannel chan<- error) {
|
|||
close(errorChannel)
|
||||
}
|
||||
|
||||
func (storage *storage) GetObjectMetadata(bucket, key string) mstorage.ObjectMetadata {
|
||||
func (storage *storage) GetObjectMetadata(bucket, key string) (mstorage.ObjectMetadata, error) {
|
||||
objectKey := bucket + ":" + key
|
||||
|
||||
return storage.objectdata[objectKey].metadata
|
||||
if object, ok := storage.objectdata[objectKey]; ok == true {
|
||||
return object.metadata, nil
|
||||
} else {
|
||||
return mstorage.ObjectMetadata{}, mstorage.ObjectNotFound{Bucket: bucket, Path: key}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ type Storage interface {
|
|||
ListBuckets(prefix string) []BucketMetadata
|
||||
|
||||
// Object Operations
|
||||
GetObjectMetadata(bucket string, object string) ObjectMetadata
|
||||
GetObjectMetadata(bucket string, object string) (ObjectMetadata, error)
|
||||
CopyObjectToWriter(w io.Writer, bucket string, object string) (int64, error)
|
||||
StoreObject(bucket string, key string, data io.Reader) error
|
||||
ListObjects(bucket, prefix string, count int) []ObjectMetadata
|
||||
|
|
|
@ -22,6 +22,7 @@ import (
|
|||
"encoding/xml"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
|
@ -47,6 +48,7 @@ func HttpHandler(storage mstorage.Storage) http.Handler {
|
|||
mux.HandleFunc("/{bucket}/", api.listObjectsHandler).Methods("GET")
|
||||
mux.HandleFunc("/{bucket}/{object:.*}", api.getObjectHandler).Methods("GET")
|
||||
mux.HandleFunc("/{bucket}/{object:.*}", api.putObjectHandler).Methods("PUT")
|
||||
mux.HandleFunc("/{bucket}/{object:.*}", api.headObjectHandler).Methods("HEAD")
|
||||
return mux
|
||||
}
|
||||
|
||||
|
@ -55,11 +57,12 @@ func (server *minioApi) getObjectHandler(w http.ResponseWriter, req *http.Reques
|
|||
bucket := vars["bucket"]
|
||||
object := vars["object"]
|
||||
|
||||
metadata := server.storage.GetObjectMetadata(bucket, object)
|
||||
metadata, err := server.storage.GetObjectMetadata(bucket, object)
|
||||
lastModified := metadata.Created.Format(time.RFC1123)
|
||||
w.Header().Set("ETag", metadata.ETag)
|
||||
w.Header().Set("Last-Modified", lastModified)
|
||||
_, err := server.storage.CopyObjectToWriter(w, bucket, object)
|
||||
w.Header().Set("Content-Length", strconv.Itoa(metadata.Size))
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
switch err := err.(type) {
|
||||
case nil: // success
|
||||
{
|
||||
|
@ -76,6 +79,33 @@ func (server *minioApi) getObjectHandler(w http.ResponseWriter, req *http.Reques
|
|||
w.WriteHeader(http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
if _, err := server.storage.CopyObjectToWriter(w, bucket, object); err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
|
||||
func (server *minioApi) headObjectHandler(w http.ResponseWriter, req *http.Request) {
|
||||
vars := mux.Vars(req)
|
||||
bucket := vars["bucket"]
|
||||
object := vars["object"]
|
||||
|
||||
metadata, err := server.storage.GetObjectMetadata(bucket, object)
|
||||
switch err := err.(type) {
|
||||
case nil: // success
|
||||
case mstorage.ObjectNotFound:
|
||||
log.Println(err)
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
return
|
||||
default:
|
||||
log.Println(err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
lastModified := metadata.Created.Format(time.RFC1123)
|
||||
w.Header().Set("ETag", metadata.ETag)
|
||||
w.Header().Set("Last-Modified", lastModified)
|
||||
w.Header().Set("Content-Length", strconv.Itoa(metadata.Size))
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
}
|
||||
|
||||
func (server *minioApi) listBucketsHandler(w http.ResponseWriter, req *http.Request) {
|
||||
|
|
Loading…
Reference in New Issue