Virtual host style S3 requests (#5095)

This commit is contained in:
Krishna Srinivas
2017-11-14 16:56:24 -08:00
committed by Dee Koder
parent d57d57ddf5
commit e7a724de0d
18 changed files with 409 additions and 159 deletions

View File

@@ -19,6 +19,7 @@ package cmd
import (
"io"
"mime/multipart"
"net"
"net/http"
"net/url"
"os"
@@ -259,3 +260,30 @@ func httpTraceHdrs(f http.HandlerFunc) http.HandlerFunc {
}
return httptracer.TraceReqHandlerFunc(f, os.Stdout, false)
}
// Returns "/bucketName/objectName" for path-style or virtual-host-style requests.
func getResource(path string, host string, domain string) (string, error) {
if domain == "" {
return path, nil
}
// If virtual-host-style is enabled construct the "resource" properly.
if strings.Contains(host, ":") {
// In bucket.mydomain.com:9000, strip out :9000
var err error
if host, _, err = net.SplitHostPort(host); err != nil {
errorIf(err, "Unable to split %s", host)
return "", err
}
}
if !strings.HasSuffix(host, "."+domain) {
return path, nil
}
bucket := strings.TrimSuffix(host, "."+domain)
return slashSeparator + pathJoin(bucket, path), nil
}
// If none of the http routes match respond with MethodNotAllowed
func notFoundHandler(w http.ResponseWriter, r *http.Request) {
writeErrorResponse(w, ErrMethodNotAllowed, r.URL)
return
}