minio/pkg/api/api_router.go

65 lines
2.6 KiB
Go
Raw Normal View History

/*
* Minimalist Object Storage, (C) 2014 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package api
import (
"net/http"
router "github.com/gorilla/mux"
2015-05-11 19:23:10 -04:00
"github.com/minio/minio/pkg/api/logging"
"github.com/minio/minio/pkg/api/quota"
"github.com/minio/minio/pkg/storage/drivers"
)
2015-02-23 19:46:48 -05:00
// private use
2015-03-06 00:07:19 -05:00
type minioAPI struct {
driver drivers.Driver
}
// HTTPHandler - http wrapper handler
func HTTPHandler(driver drivers.Driver) http.Handler {
var mux *router.Router
var api = minioAPI{}
api.driver = driver
mux = router.NewRouter()
mux.HandleFunc("/", api.listBucketsHandler).Methods("GET")
mux.HandleFunc("/{bucket}", api.listObjectsHandler).Methods("GET")
mux.HandleFunc("/{bucket}", api.putBucketHandler).Methods("PUT")
mux.HandleFunc("/{bucket}", api.headBucketHandler).Methods("HEAD")
mux.HandleFunc("/{bucket}/{object:.*}", api.headObjectHandler).Methods("HEAD")
mux.HandleFunc("/{bucket}/{object:.*}", api.putObjectPartHandler).Queries("partNumber", "{partNumber:[0-9]+}", "uploadId", "{uploadId:.*}").Methods("PUT")
mux.HandleFunc("/{bucket}/{object:.*}", api.listObjectPartsHandler).Queries("uploadId", "{uploadId:.*}").Methods("GET")
mux.HandleFunc("/{bucket}/{object:.*}", api.completeMultipartUploadHandler).Queries("uploadId", "{uploadId:.*}").Methods("POST")
mux.HandleFunc("/{bucket}/{object:.*}", api.newMultipartUploadHandler).Methods("POST")
mux.HandleFunc("/{bucket}/{object:.*}", api.abortMultipartUploadHandler).Queries("uploadId", "{uploadId:.*}").Methods("DELETE")
2015-05-09 14:41:26 -04:00
mux.HandleFunc("/{bucket}/{object:.*}", api.getObjectHandler).Methods("GET")
mux.HandleFunc("/{bucket}/{object:.*}", api.putObjectHandler).Methods("PUT")
h := validContentTypeHandler(mux)
h = timeValidityHandler(h)
h = ignoreResourcesHandler(h)
h = validateAuthHeaderHandler(h)
// h = quota.BandwidthCap(h, 25*1024*1024, time.Duration(30*time.Minute))
// h = quota.BandwidthCap(h, 100*1024*1024, time.Duration(24*time.Hour))
// h = quota.RequestLimit(h, 100, time.Duration(30*time.Minute))
// h = quota.RequestLimit(h, 1000, time.Duration(24*time.Hour))
2015-05-14 02:05:48 -04:00
h = quota.ConnectionLimit(h, 4)
2015-04-29 15:24:53 -04:00
h = logging.LogHandler(h)
return h
}