diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2023-01-31 09:28:21 +0100 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2023-01-31 09:28:21 +0100 |
| commit | d9a874765ce847e93223bc31e2efc9166312e11a (patch) | |
| tree | 1e8b059fea12e0ace200fc2c8fe60ed88e42bdb0 /internal/http/http.go | |
| parent | b320b13b5d019c26928d2f00d8cba0febacb104b (diff) | |
HTTP + Util: Always set the scheme to HTTPS
Diffstat (limited to 'internal/http/http.go')
| -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. |
