diff options
Diffstat (limited to 'internal/http')
| -rw-r--r-- | internal/http/http.go | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/internal/http/http.go b/internal/http/http.go index 201db91..58d69bf 100644 --- a/internal/http/http.go +++ b/internal/http/http.go @@ -25,13 +25,7 @@ type OptionalParams struct { } // ConstructURL creates a URL with the included parameters. -func ConstructURL(baseURL string, params URLParameters) (string, error) { - u, err := url.Parse(baseURL) - if err != nil { - return "", errors.WrapPrefix(err, - fmt.Sprintf("failed to construct url '%s' with parameters: %v", u, params), 0) - } - +func ConstructURL(u *url.URL, params URLParameters) (string, error) { q := u.Query() for p, value := range params { @@ -44,11 +38,21 @@ func ConstructURL(baseURL string, params URLParameters) (string, error) { // optionalURL ensures that the URL contains the optional parameters // it returns the url (with parameters if success) and an error indicating success. func optionalURL(urlStr string, opts *OptionalParams) (string, error) { + u, err := url.Parse(urlStr) + if err != nil { + return "", errors.WrapPrefix(err, + fmt.Sprintf("failed to construct parse url '%s'", urlStr), 0) + } + // Make sure the scheme is always set to HTTPS + if u.Scheme != "https" { + u.Scheme = "https" + } + if opts == nil { - return urlStr, nil + return u.String(), nil } - return ConstructURL(urlStr, opts.URLParameters) + return ConstructURL(u, opts.URLParameters) } // optionalHeaders ensures that the HTTP request uses the optional headers if defined. |
