Allow user to specify protocol for custom endpoint

In local setups, such as a Minio [1] instance in a Docker container,
the protocol may not always be HTTPS (like for public production
endpoints), but instead just plain HTTP.
To support this use-case, the user can specify a protocol at the
beginning of the custom endpoint URI (either http:// or https://).

To maintain backwards compatibility, the protocol defaults to HTTPS.

The patch also includes a test case to assert this behavior.

[1] https://hub.docker.com/r/minio/minio
This commit is contained in:
Jack Henschel
2020-09-15 09:04:34 +02:00
parent 2a542b05fe
commit 2c7094bdb6
2 changed files with 27 additions and 1 deletions
+5 -1
View File
@@ -155,7 +155,7 @@ func (s3 *S3) getClient() *http.Client {
func (s3 *S3) getURL(bucket string, args ...string) (uri string) {
if len(s3.Endpoint) > 0 {
uri = defaultProtocol + s3.Endpoint + "/" + bucket
uri = s3.Endpoint + "/" + bucket
} else {
uri = fmt.Sprintf(s3.URIFormat, s3.Region, bucket)
}
@@ -168,8 +168,12 @@ func (s3 *S3) getURL(bucket string, args ...string) (uri string) {
// SetEndpoint can be used to the set a custom endpoint for
// using an alternate instance compatible with the s3 API.
// If no protocol is included in the URI, defaults to HTTPS.
func (s3 *S3) SetEndpoint(uri string) *S3 {
if len(uri) > 0 {
if !strings.HasPrefix(uri, "http") {
uri = "https://" + uri
}
s3.Endpoint = uri
}
return s3