aboutsummaryrefslogtreecommitdiff
path: root/client.go
diff options
context:
space:
mode:
authorAdnan Maolood <[email protected]>2021-02-21 09:43:23 -0500
committerAdnan Maolood <[email protected]>2021-02-21 09:43:23 -0500
commit2ece48b0193d50a75ef92e956563cd60df7fca4f (patch)
tree6adce70c2ac6909fd1fbce8a9ddc2efecf4791ca /client.go
parentclient: Copy only what is needed from the Request (diff)
downloadgo-gemini-2ece48b0193d50a75ef92e956563cd60df7fca4f.tar.xz
go-gemini-2ece48b0193d50a75ef92e956563cd60df7fca4f.zip
Move punycode functions to client.go
Diffstat (limited to 'client.go')
-rw-r--r--client.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/client.go b/client.go
index 9d79832..97a35bb 100644
--- a/client.go
+++ b/client.go
@@ -7,6 +7,9 @@ import (
"net"
"net/url"
"time"
+ "unicode/utf8"
+
+ "golang.org/x/net/idna"
)
// A Client is a Gemini client. Its zero value is a usable client.
@@ -202,3 +205,23 @@ func splitHostPort(hostport string) (host, port string) {
}
return
}
+
+func isASCII(s string) bool {
+ for i := 0; i < len(s); i++ {
+ if s[i] >= utf8.RuneSelf {
+ return false
+ }
+ }
+ return true
+}
+
+// punycodeHostname returns the punycoded version of hostname.
+func punycodeHostname(hostname string) (string, error) {
+ if net.ParseIP(hostname) != nil {
+ return hostname, nil
+ }
+ if isASCII(hostname) {
+ return hostname, nil
+ }
+ return idna.Lookup.ToASCII(hostname)
+}