From 3eee57a9666e53e955ab157a119eedfa6031144c Mon Sep 17 00:00:00 2001 From: keep94 Date: Thu, 18 Mar 2021 16:08:47 -0700 Subject: [PATCH] Bug fix: undesired behavior if domain starts with http. (#42) We still want to prepend 'https://' even if the domain starts with http. --- client.go | 2 +- client_test.go | 12 ++++++++++++ version | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/client.go b/client.go index 1acf8301..433abd5d 100644 --- a/client.go +++ b/client.go @@ -62,7 +62,7 @@ type Client struct { } func fixAddress(address string) string { - if !strings.HasPrefix(address, "http") { + if !strings.HasPrefix(address, "http://") && !strings.HasPrefix(address, "https://") { address = "https://" + address } return address + "/api/v2/" diff --git a/client_test.go b/client_test.go index 9900ddd3..6d1a3e50 100644 --- a/client_test.go +++ b/client_test.go @@ -299,6 +299,18 @@ func TestHttpConnection(t *testing.T) { assert.Equal("http://localhost:8080/api/v2/", client.BaseURL.String()) } +func TestHttpInDomain(t *testing.T) { + assert := asserts.New(t) + config := &Config{ + Address: "httpserver.com", + Token: "987654321", + SkipTLSVerify: true, + } + client, err := NewClient(config) + assert.NoError(err) + assert.Equal("https://httpserver.com/api/v2/", client.BaseURL.String()) +} + func TestDoRest_DirectResponse(t *testing.T) { responseStr := ` { diff --git a/version b/version index 850e7424..a4cc5571 100644 --- a/version +++ b/version @@ -1 +1 @@ -1.14.0 +1.14.2