diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2023-02-17 13:29:19 +0100 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2023-02-17 13:29:19 +0100 |
| commit | cdd4a721cc891b8210267eb70a392e10e86ab706 (patch) | |
| tree | 226b537eea7cb8592edadf3175f2daedd8e0e204 /internal | |
| parent | 54d8b3868c26fa32678f189095fb6c849a3a9a9f (diff) | |
HTTP: Only add trailing slash for ensuring valid URL
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/http/http.go | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/internal/http/http.go b/internal/http/http.go index 9b45733..995b36f 100644 --- a/internal/http/http.go +++ b/internal/http/http.go @@ -25,7 +25,7 @@ type OptionalParams struct { Timeout time.Duration } -func cleanPath(u *url.URL) string { +func cleanPath(u *url.URL, trailing bool) string { if u.Path != "" { // Clean the path // https://pkg.go.dev/path#Clean @@ -35,7 +35,7 @@ func cleanPath(u *url.URL) string { str := u.String() // Make sure the URL ends with a / - if str[len(str)-1:] != "/" { + if trailing && str[len(str)-1:] != "/" { str += "/" } return str @@ -57,7 +57,7 @@ func EnsureValidURL(s string) (string, error) { if u.Scheme != "https" { u.Scheme = "https" } - return cleanPath(u), nil + return cleanPath(u, true), nil } // JoinURLPath joins url's path, in go 1.19 we can use url.JoinPath @@ -73,7 +73,7 @@ func JoinURLPath(u string, p string) (string, error) { fp := pu.ResolveReference(pp) // We also clean the path for consistency - return cleanPath(fp), nil + return cleanPath(fp, false), nil } // ConstructURL creates a URL with the included parameters. |
