Skip to content

Commit

Permalink
fix client host scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
ezekg committed Mar 12, 2024
1 parent c594df2 commit aab6687
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,21 @@ func (c *Client) new(method string, path string, params interface{}) (*http.Requ
c.APIURL = APIURL
}

// Local vars so we don't mutate the client
account := c.Account
prefix := c.APIPrefix
host := c.APIURL

// Add scheme if not present (e.g. with self-hosted KEYGEN_HOST env var via the CLI)
if !strings.HasPrefix(c.APIURL, "https://") && !strings.HasPrefix(c.APIURL, "http://") {
c.APIURL = "https://" + c.APIURL
if !strings.HasPrefix(host, "https://") && !strings.HasPrefix(host, "http://") {
host = "https://" + host
}

// Support for custom domains
if c.APIURL == "https://api.keygen.sh" {
url = fmt.Sprintf("%s/%s/accounts/%s/%s", c.APIURL, c.APIPrefix, c.Account, path)
if host == "https://api.keygen.sh" {
url = fmt.Sprintf("%s/%s/accounts/%s/%s", host, prefix, account, path)
} else {
url = fmt.Sprintf("%s/%s/%s", c.APIURL, c.APIPrefix, path)
url = fmt.Sprintf("%s/%s/%s", host, prefix, path)
}

ua := strings.Join([]string{userAgent, c.UserAgent}, " ")
Expand Down

0 comments on commit aab6687

Please sign in to comment.