summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2023-01-31 09:28:21 +0100
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2023-01-31 09:28:21 +0100
commitd9a874765ce847e93223bc31e2efc9166312e11a (patch)
tree1e8b059fea12e0ace200fc2c8fe60ed88e42bdb0 /internal
parentb320b13b5d019c26928d2f00d8cba0febacb104b (diff)
HTTP + Util: Always set the scheme to HTTPS
Diffstat (limited to 'internal')
-rw-r--r--internal/http/http.go22
-rw-r--r--internal/oauth/oauth.go7
-rw-r--r--internal/util/util.go3
3 files changed, 21 insertions, 11 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.
diff --git a/internal/oauth/oauth.go b/internal/oauth/oauth.go
index 924b434..c11179c 100644
--- a/internal/oauth/oauth.go
+++ b/internal/oauth/oauth.go
@@ -490,7 +490,12 @@ func (oauth *OAuth) AuthURL(name string, postProcessAuth func(string) string) (s
"redirect_uri": fmt.Sprintf("http://127.0.0.1:%d/callback", port),
}
- u, err := httpw.ConstructURL(oauth.BaseAuthorizationURL, params)
+ p, err := url.Parse(oauth.BaseAuthorizationURL)
+ if err != nil {
+ return "", errors.WrapPrefix(err, fmt.Sprintf("failed to parse OAuth base URL '%s'", oauth.BaseAuthorizationURL), 0)
+ }
+
+ u, err := httpw.ConstructURL(p, params)
if err != nil {
return "", errors.WrapPrefix(err, "httpw.ConstructURL error", 0)
}
diff --git a/internal/util/util.go b/internal/util/util.go
index 01b2f21..4370fd1 100644
--- a/internal/util/util.go
+++ b/internal/util/util.go
@@ -24,7 +24,8 @@ func EnsureValidURL(s string) (string, error) {
return "", errors.WrapPrefix(err, "failed parsing url", 0)
}
- if u.Scheme == "" {
+ // Make sure the scheme is always https
+ if u.Scheme != "https" {
u.Scheme = "https"
}
if u.Path != "" {