Skip to content

Commit

Permalink
Bug fix: undesired behavior if domain starts with http. (#42)
Browse files Browse the repository at this point in the history
We still want to prepend 'https://' even if the domain starts with http.
  • Loading branch information
keep94 authored Mar 18, 2021
1 parent 8ee4fdb commit 3eee57a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand Down
12 changes: 12 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 := `
{
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.14.0
1.14.2

0 comments on commit 3eee57a

Please sign in to comment.