From d9a874765ce847e93223bc31e2efc9166312e11a Mon Sep 17 00:00:00 2001 From: jwijenbergh Date: Tue, 31 Jan 2023 09:28:21 +0100 Subject: HTTP + Util: Always set the scheme to HTTPS --- internal/http/http.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'internal/http') 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. -- cgit v1.2.3