mirror of
https://github.com/minio/minio.git
synced 2024-12-28 08:05:55 -05:00
51e80eaa6d
This change brings in domain and subdomain support - ./minio --domain "yourminiodomain.com" This change brings in a much needed feature by keeping bucketnames as part of your 'DNS' name. All your existing applications can be migrated off from s3 to Minio without little to no modifications. NOTE: Setting up DNS for your `buckets` is out of scope of this feature
133 lines
3.8 KiB
Go
133 lines
3.8 KiB
Go
package minioapi
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
|
|
"github.com/gorilla/mux"
|
|
mstorage "github.com/minio-io/minio/pkg/storage"
|
|
)
|
|
|
|
func (server *minioApi) listObjectsHandler(w http.ResponseWriter, req *http.Request) {
|
|
vars := mux.Vars(req)
|
|
bucket := vars["bucket"]
|
|
|
|
resources := getBucketResources(req.URL.Query())
|
|
if resources.policy == true {
|
|
server.getBucketPolicyHandler(w, req)
|
|
return
|
|
}
|
|
|
|
acceptsContentType := getContentType(req)
|
|
objects, isTruncated, err := server.storage.ListObjects(bucket, resources.prefix, 1000)
|
|
switch err := err.(type) {
|
|
case nil: // success
|
|
{
|
|
response := generateObjectsListResult(bucket, objects, isTruncated)
|
|
w.Write(writeObjectHeadersAndResponse(w, response, acceptsContentType))
|
|
}
|
|
case mstorage.BucketNotFound:
|
|
{
|
|
error := errorCodeError(NoSuchBucket)
|
|
errorResponse := getErrorResponse(error, bucket)
|
|
w.WriteHeader(error.HttpStatusCode)
|
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
|
}
|
|
case mstorage.ImplementationError:
|
|
{
|
|
// Embed error log on server side
|
|
log.Println(err)
|
|
error := errorCodeError(InternalError)
|
|
errorResponse := getErrorResponse(error, bucket)
|
|
w.WriteHeader(error.HttpStatusCode)
|
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
|
}
|
|
case mstorage.BucketNameInvalid:
|
|
{
|
|
error := errorCodeError(InvalidBucketName)
|
|
errorResponse := getErrorResponse(error, bucket)
|
|
w.WriteHeader(error.HttpStatusCode)
|
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
|
}
|
|
case mstorage.ObjectNameInvalid:
|
|
{
|
|
error := errorCodeError(NoSuchKey)
|
|
errorResponse := getErrorResponse(error, resources.prefix)
|
|
w.WriteHeader(error.HttpStatusCode)
|
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
|
}
|
|
}
|
|
}
|
|
|
|
func (server *minioApi) listBucketsHandler(w http.ResponseWriter, req *http.Request) {
|
|
acceptsContentType := getContentType(req)
|
|
buckets, err := server.storage.ListBuckets()
|
|
switch err := err.(type) {
|
|
case nil:
|
|
{
|
|
response := generateBucketsListResult(buckets)
|
|
w.Write(writeObjectHeadersAndResponse(w, response, acceptsContentType))
|
|
}
|
|
case mstorage.ImplementationError:
|
|
{
|
|
log.Println(err)
|
|
error := errorCodeError(InternalError)
|
|
errorResponse := getErrorResponse(error, "")
|
|
w.WriteHeader(error.HttpStatusCode)
|
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
|
}
|
|
case mstorage.BackendCorrupted:
|
|
{
|
|
log.Println(err)
|
|
error := errorCodeError(InternalError)
|
|
errorResponse := getErrorResponse(error, "")
|
|
w.WriteHeader(error.HttpStatusCode)
|
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
|
}
|
|
}
|
|
}
|
|
|
|
func (server *minioApi) putBucketHandler(w http.ResponseWriter, req *http.Request) {
|
|
vars := mux.Vars(req)
|
|
bucket := vars["bucket"]
|
|
err := server.storage.StoreBucket(bucket)
|
|
|
|
resources := getBucketResources(req.URL.Query())
|
|
if resources.policy == true {
|
|
server.putBucketPolicyHandler(w, req)
|
|
return
|
|
}
|
|
|
|
acceptsContentType := getContentType(req)
|
|
switch err := err.(type) {
|
|
case nil:
|
|
{
|
|
w.Header().Set("Server", "Minio")
|
|
w.Header().Set("Connection", "close")
|
|
}
|
|
case mstorage.BucketNameInvalid:
|
|
{
|
|
error := errorCodeError(InvalidBucketName)
|
|
errorResponse := getErrorResponse(error, bucket)
|
|
w.WriteHeader(error.HttpStatusCode)
|
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
|
}
|
|
case mstorage.BucketExists:
|
|
{
|
|
error := errorCodeError(BucketAlreadyExists)
|
|
errorResponse := getErrorResponse(error, bucket)
|
|
w.WriteHeader(error.HttpStatusCode)
|
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
|
}
|
|
case mstorage.ImplementationError:
|
|
{
|
|
// Embed errors log on server side
|
|
log.Println(err)
|
|
error := errorCodeError(InternalError)
|
|
errorResponse := getErrorResponse(error, bucket)
|
|
w.WriteHeader(error.HttpStatusCode)
|
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
|
}
|
|
}
|
|
}
|