From 75ac9ee246e7d3be5890b972a241855da875f4b0 Mon Sep 17 00:00:00 2001 From: jwijenbergh Date: Thu, 16 Feb 2023 15:44:08 +0100 Subject: HTTP: Incorporate util ensure valid url with clean path --- internal/util/util.go | 32 -------------------------------- 1 file changed, 32 deletions(-) (limited to 'internal/util/util.go') diff --git a/internal/util/util.go b/internal/util/util.go index 4370fd1..907f85f 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -6,43 +6,11 @@ import ( "fmt" "net/url" "os" - "path" "strings" "github.com/go-errors/errors" ) -// EnsureValidURL ensures that the input URL is valid to be used internally -// It does the following -// - Sets the scheme to https if none is given -// - It 'cleans' up the path using path.Clean -// - It makes sure that the URL ends with a / -// It returns an error if the URL cannot be parsed. -func EnsureValidURL(s string) (string, error) { - u, err := url.Parse(s) - if err != nil { - return "", errors.WrapPrefix(err, "failed parsing url", 0) - } - - // Make sure the scheme is always https - if u.Scheme != "https" { - u.Scheme = "https" - } - if u.Path != "" { - // Clean the path - // https://pkg.go.dev/path#Clean - u.Path = path.Clean(u.Path) - } - - str := u.String() - - // Make sure the URL ends with a / - if str[len(str)-1:] != "/" { - str += "/" - } - return str, nil -} - // MakeRandomByteSlice creates a cryptographically random bytes slice of `size` // It returns the byte slice (or nil if error) and an error if it could not be generated. func MakeRandomByteSlice(n int) ([]byte, error) { -- cgit v1.2.3