net/http/httpproxy: support non-ASCII characters in NO_PROXY

Change-Id: I4b3a97a2046fcc2619535a508c9d71ffa4ca75df
GitHub-Last-Rev: 5e2316523ccaa29273e68b9c12e50f2fce36967c
GitHub-Pull-Request: golang/net#105
Reviewed-on: https://go-review.googlesource.com/c/net/+/326269
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Trust: Brad Fitzpatrick <bradfitz@golang.org>
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
diff --git a/http/httpproxy/proxy.go b/http/httpproxy/proxy.go
index d2c8c87..16994ac 100644
--- a/http/httpproxy/proxy.go
+++ b/http/httpproxy/proxy.go
@@ -267,6 +267,9 @@
 			matchHost = true
 			phost = "." + phost
 		}
+		if v, err := idnaASCII(phost); err == nil {
+			phost = v
+		}
 		c.domainMatchers = append(c.domainMatchers, domainMatch{host: phost, port: pport, matchHost: matchHost})
 	}
 }
diff --git a/http/httpproxy/proxy_test.go b/http/httpproxy/proxy_test.go
index 2a12dad..d763732 100644
--- a/http/httpproxy/proxy_test.go
+++ b/http/httpproxy/proxy_test.go
@@ -178,7 +178,29 @@
 	},
 	req:  "http://example.com/",
 	want: "http://proxy",
-}}
+}, {
+	cfg: httpproxy.Config{
+		NoProxy:   ".示例.com",
+		HTTPProxy: "proxy",
+	},
+	req:  "http://www.示例.com",
+	want: "<nil>",
+}, {
+	cfg: httpproxy.Config{
+		NoProxy:   "xn--fsq092h.com",
+		HTTPProxy: "proxy",
+	},
+	req:  "http://www.示例.com",
+	want: "<nil>",
+}, {
+	cfg: httpproxy.Config{
+		NoProxy:   "示例.com",
+		HTTPProxy: "proxy",
+	},
+	req:  "http://www.xn--fsq092h.com",
+	want: "<nil>",
+},
+}
 
 func testProxyForURL(t *testing.T, tt proxyForURLTest) {
 	setHelper(t)