Pull request: all: mv some utilities to netutil

Merge in DNS/adguard-home from mv-netutil to master

Squashed commit of the following:

commit 5698fceed656dca7f8644e7dbd7e1a7fc57a68ce
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Mon Aug 9 15:44:17 2021 +0300

    dnsforward: add todos

commit 122fb6e3de658b296931e0f608cf24ef85547666
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Mon Aug 9 14:27:46 2021 +0300

    all: mv some utilities to netutil
This commit is contained in:
Ainar Garipov
2021-08-09 16:03:37 +03:00
parent 133a1c57b1
commit 9bd7294fad
37 changed files with 242 additions and 1033 deletions

View File

@@ -13,6 +13,7 @@ import (
"github.com/AdguardTeam/AdGuardHome/internal/dnsforward"
"github.com/AdguardTeam/AdGuardHome/internal/version"
"github.com/AdguardTeam/golibs/log"
"github.com/AdguardTeam/golibs/netutil"
"github.com/NYTimes/gziphandler"
)
@@ -39,7 +40,7 @@ func appendDNSAddrs(dst []string, addrs ...net.IP) (res []string) {
for _, addr := range addrs {
var hostport string
if config.DNS.Port != 53 {
hostport = aghnet.JoinHostPort(addr.String(), config.DNS.Port)
hostport = netutil.JoinHostPort(addr.String(), config.DNS.Port)
} else {
hostport = addr.String()
}
@@ -294,7 +295,7 @@ func handleHTTPSRedirect(w http.ResponseWriter, r *http.Request) (ok bool) {
return true
}
host, err := aghnet.SplitHost(r.Host)
host, err := netutil.SplitHost(r.Host)
if err != nil {
httpError(w, http.StatusBadRequest, "bad host: %s", err)
@@ -304,7 +305,7 @@ func handleHTTPSRedirect(w http.ResponseWriter, r *http.Request) (ok bool) {
if r.TLS == nil && web.forceHTTPS {
hostPort := host
if port := web.conf.PortHTTPS; port != defaultHTTPSPort {
hostPort = aghnet.JoinHostPort(host, port)
hostPort = netutil.JoinHostPort(host, port)
}
httpsURL := &url.URL{