Merge pull request #999 from harshavardhana/acl

ignore-handlers: Enhance ignore handlers to cater for bucket resource…
master
Harshavardhana 9 years ago
commit a97c4ebce3
  1. 1
      api-definitions.go
  2. 33
      generic-handlers.go

@ -199,7 +199,6 @@ var notimplementedBucketResourceNames = map[string]bool{
"policy": true, "policy": true,
"cors": true, "cors": true,
"lifecycle": true, "lifecycle": true,
"location": true,
"logging": true, "logging": true,
"notification": true, "notification": true,
"replication": true, "replication": true,

@ -136,27 +136,40 @@ func IgnoreResourcesHandler(h http.Handler) http.Handler {
return resourceHandler{h} return resourceHandler{h}
} }
const (
separator = "/"
)
// Resource handler ServeHTTP() wrapper // Resource handler ServeHTTP() wrapper
func (h resourceHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (h resourceHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
splits := strings.SplitN(r.URL.Path, separator, 3) // Skip the first element which is usally '/' and split the rest.
switch len(splits) { splits := strings.SplitN(r.URL.Path[1:], "/", 2)
// bucket exists
case 2: // Save bucketName and objectName extracted from url Path.
var bucketName, objectName string
if len(splits) == 1 {
bucketName = splits[0]
}
if len(splits) == 2 {
bucketName = splits[0]
objectName = splits[1]
}
// If bucketName is present and not objectName check for bucket
// level resource queries.
if bucketName != "" && objectName == "" {
if ignoreNotImplementedBucketResources(r) { if ignoreNotImplementedBucketResources(r) {
writeErrorResponse(w, r, NotImplemented, r.URL.Path) writeErrorResponse(w, r, NotImplemented, r.URL.Path)
return return
} }
// object exists }
case 3: // If bucketName and objectName are present check for its resource queries.
if bucketName != "" && objectName != "" {
if ignoreNotImplementedObjectResources(r) { if ignoreNotImplementedObjectResources(r) {
writeErrorResponse(w, r, NotImplemented, r.URL.Path) writeErrorResponse(w, r, NotImplemented, r.URL.Path)
return return
} }
} }
// A put method on path "/" doesn't make sense, ignore it.
if r.Method == "PUT" && r.URL.Path == "/" {
writeErrorResponse(w, r, NotImplemented, r.URL.Path)
return
}
h.handler.ServeHTTP(w, r) h.handler.ServeHTTP(w, r)
} }

Loading…
Cancel
Save