2015-02-15 17:03:27 -08:00
|
|
|
/*
|
2015-03-19 14:35:50 -07:00
|
|
|
* Minimalist Object Storage, (C) 2014 Minio, Inc.
|
2015-02-15 17:03:27 -08:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2015-03-18 17:49:33 -07:00
|
|
|
package api
|
2015-02-15 17:03:27 -08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
|
2015-03-18 22:49:02 -07:00
|
|
|
router "github.com/gorilla/mux"
|
2015-05-11 16:23:10 -07:00
|
|
|
"github.com/minio/minio/pkg/api/logging"
|
|
|
|
"github.com/minio/minio/pkg/api/quota"
|
|
|
|
"github.com/minio/minio/pkg/featureflags"
|
|
|
|
"github.com/minio/minio/pkg/storage/drivers"
|
2015-02-15 17:03:27 -08:00
|
|
|
)
|
|
|
|
|
2015-02-23 16:46:48 -08:00
|
|
|
// private use
|
2015-03-05 21:07:19 -08:00
|
|
|
type minioAPI struct {
|
2015-03-23 20:40:21 -07:00
|
|
|
driver drivers.Driver
|
2015-02-15 17:03:27 -08:00
|
|
|
}
|
|
|
|
|
2015-05-07 00:14:58 -07:00
|
|
|
// HTTPHandler - http wrapper handler
|
|
|
|
func HTTPHandler(driver drivers.Driver) http.Handler {
|
|
|
|
var mux *router.Router
|
|
|
|
var api = minioAPI{}
|
|
|
|
api.driver = driver
|
|
|
|
|
|
|
|
mux = router.NewRouter()
|
2015-02-23 02:11:27 -08:00
|
|
|
mux.HandleFunc("/", api.listBucketsHandler).Methods("GET")
|
|
|
|
mux.HandleFunc("/{bucket}", api.listObjectsHandler).Methods("GET")
|
|
|
|
mux.HandleFunc("/{bucket}", api.putBucketHandler).Methods("PUT")
|
2015-04-07 00:44:01 -07:00
|
|
|
mux.HandleFunc("/{bucket}", api.headBucketHandler).Methods("HEAD")
|
2015-02-23 02:11:27 -08:00
|
|
|
mux.HandleFunc("/{bucket}/{object:.*}", api.headObjectHandler).Methods("HEAD")
|
2015-05-07 19:55:30 -07:00
|
|
|
if featureflags.Get(featureflags.MultipartPutObject) {
|
|
|
|
log.Println("Enabling feature", featureflags.MultipartPutObject)
|
2015-05-09 17:42:14 -07:00
|
|
|
mux.HandleFunc("/{bucket}/{object:.*}", api.putObjectPartHandler).Queries("partNumber", "{partNumber:[0-9]+}", "uploadId", "{uploadId:.*}").Methods("PUT")
|
2015-05-09 11:41:26 -07:00
|
|
|
mux.HandleFunc("/{bucket}/{object:.*}", api.listObjectPartsHandler).Queries("uploadId", "{uploadId:.*}").Methods("GET")
|
2015-05-07 19:55:30 -07:00
|
|
|
mux.HandleFunc("/{bucket}/{object:.*}", api.completeMultipartUploadHandler).Queries("uploadId", "{uploadId:.*}").Methods("POST")
|
2015-05-07 21:37:34 -07:00
|
|
|
mux.HandleFunc("/{bucket}/{object:.*}", api.newMultipartUploadHandler).Methods("POST")
|
2015-05-09 16:06:35 -07:00
|
|
|
mux.HandleFunc("/{bucket}/{object:.*}", api.abortMultipartUploadHandler).Queries("uploadId", "{uploadId:.*}").Methods("DELETE")
|
2015-05-07 19:55:30 -07:00
|
|
|
}
|
2015-05-09 11:41:26 -07:00
|
|
|
mux.HandleFunc("/{bucket}/{object:.*}", api.getObjectHandler).Methods("GET")
|
2015-02-23 02:11:27 -08:00
|
|
|
mux.HandleFunc("/{bucket}/{object:.*}", api.putObjectHandler).Methods("PUT")
|
|
|
|
|
2015-05-13 12:19:41 -07:00
|
|
|
h := validContentTypeHandler(mux)
|
|
|
|
h = timeValidityHandler(h)
|
2015-04-27 03:54:49 -07:00
|
|
|
h = ignoreResourcesHandler(h)
|
2015-05-13 12:19:41 -07:00
|
|
|
h = validateAuthHeaderHandler(h)
|
2015-04-27 21:56:43 -07:00
|
|
|
// 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-11 14:24:12 -07:00
|
|
|
h = quota.ConnectionLimit(h, 5)
|
2015-04-29 12:24:53 -07:00
|
|
|
h = logging.LogHandler(h)
|
2015-04-26 14:20:24 -07:00
|
|
|
return h
|
2015-02-15 17:03:27 -08:00
|
|
|
}
|