IPv6: Support host address configured with enclosing square brackets (#31226) (#31228)

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
(cherry picked from commit d27a72f859)

Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
Grot (@grafanabot)andArve Knudsen authored and GitHub committed 2021-02-15 18:21:47 +01:00
1 parent dda38c55e5
commit c4774ec6ae
2 files changed
+6 -1

No files matched your search

+4 -1
View File
@@ -10,6 +10,7 @@ import (
"os"
"path"
"path/filepath"
"strings"
"sync"
"github.com/grafana/grafana/pkg/services/live"
@@ -103,8 +104,10 @@ func (hs *HTTPServer) Run(ctx context.Context) error {
hs.applyRoutes()
// Remove any square brackets enclosing IPv6 addresses, a format we support for backwards compatibility
host := strings.TrimSuffix(strings.TrimPrefix(setting.HttpAddr, "["), "]")
hs.httpSrv = &http.Server{
Addr: net.JoinHostPort(setting.HttpAddr, setting.HttpPort),
Addr: net.JoinHostPort(host, setting.HttpPort),
Handler: hs.macaron,
}
switch hs.Cfg.Protocol {
+2
View File
@@ -114,6 +114,8 @@ func (server *Server) Dial() error {
}
}
for _, host := range strings.Split(server.Config.Host, " ") {
// Remove any square brackets enclosing IPv6 addresses, a format we support for backwards compatibility
host = strings.TrimSuffix(strings.TrimPrefix(host, "["), "]")
address := net.JoinHostPort(host, strconv.Itoa(server.Config.Port))
if server.Config.UseSSL {
tlsCfg := &tls.Config{