Wrote url normalizer function.

This commit is contained in:
Jay
2026-04-14 17:27:20 -04:00
parent c4dc9a688b
commit 6d9b0ebdd4
2 changed files with 92 additions and 0 deletions

20
url.go
View File

@@ -2,6 +2,7 @@ package honeybee
import (
"net/url"
"strings"
"git.wisehodl.dev/jay/go-honeybee/errors"
)
@@ -18,3 +19,22 @@ func ParseURL(urlStr string) (*url.URL, error) {
return parsedURL, nil
}
func NormalizeURL(input string) (string, error) {
parsed, err := ParseURL(strings.ToLower(input))
if err != nil {
return "", err
}
host := parsed.Hostname()
port := parsed.Port()
if (parsed.Scheme == "wss" && port == "443") ||
(parsed.Scheme == "ws" && port == "80") {
parsed.Host = host
}
parsed.Path = strings.TrimRight(parsed.Path, "/")
return parsed.String(), nil
}