From 0462d30807792b2154202b7c3fb8ab96e143c151 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Tue, 29 Sep 2015 00:39:10 -0700 Subject: [PATCH] Add proper comment for virtual styled host --- pkg/client/s3v2/s3v2.go | 8 ++++++-- pkg/client/s3v4/s3v4.go | 9 ++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/pkg/client/s3v2/s3v2.go b/pkg/client/s3v2/s3v2.go index bc2c2a1b..87520620 100644 --- a/pkg/client/s3v2/s3v2.go +++ b/pkg/client/s3v2/s3v2.go @@ -199,10 +199,14 @@ func (c *s3Client) Stat() (*client.Content, *probe.Error) { // url2BucketAndObject gives bucketName and objectName from URL path func (c *s3Client) url2BucketAndObject() (bucketName, objectName string) { - // convert any virtual host styled requests path := c.hostURL.Path + // Convert any virtual host styled requests + // + // For the time being this check is introduced for S3, + // if you have custom virtual styled hosts please. list them below match, _ := filepath.Match("*.s3*.amazonaws.com", c.hostURL.Host) - if match { + switch { + case match == true: hostSplits := strings.SplitN(c.hostURL.Host, ".", 2) path = string(c.hostURL.Separator) + hostSplits[0] + c.hostURL.Path } diff --git a/pkg/client/s3v4/s3v4.go b/pkg/client/s3v4/s3v4.go index 075ec518..234291c0 100644 --- a/pkg/client/s3v4/s3v4.go +++ b/pkg/client/s3v4/s3v4.go @@ -199,14 +199,17 @@ func (c *s3Client) Stat() (*client.Content, *probe.Error) { // url2BucketAndObject gives bucketName and objectName from URL path func (c *s3Client) url2BucketAndObject() (bucketName, objectName string) { - // convert any virtual host styled requests path := c.hostURL.Path + // Convert any virtual host styled requests + // + // For the time being this check is introduced for S3, + // if you have custom virtual styled hosts please. list them below match, _ := filepath.Match("*.s3*.amazonaws.com", c.hostURL.Host) - if match { + switch { + case match == true: hostSplits := strings.SplitN(c.hostURL.Host, ".", 2) path = string(c.hostURL.Separator) + hostSplits[0] + c.hostURL.Path } - splits := strings.SplitN(path, string(c.hostURL.Separator), 3) switch len(splits) { case 0, 1: