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

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
pull/31208/merge
Arve Knudsen 5 years ago committed by GitHub
parent d56c5285e2
commit d27a72f859
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      pkg/api/http_server.go
  2. 2
      pkg/services/ldap/ldap.go

@ -10,6 +10,7 @@ import (
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
"strings"
"sync" "sync"
"github.com/grafana/grafana/pkg/services/live" "github.com/grafana/grafana/pkg/services/live"
@ -103,8 +104,10 @@ func (hs *HTTPServer) Run(ctx context.Context) error {
hs.applyRoutes() 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{ hs.httpSrv = &http.Server{
Addr: net.JoinHostPort(setting.HttpAddr, setting.HttpPort), Addr: net.JoinHostPort(host, setting.HttpPort),
Handler: hs.macaron, Handler: hs.macaron,
} }
switch hs.Cfg.Protocol { switch hs.Cfg.Protocol {

@ -114,6 +114,8 @@ func (server *Server) Dial() error {
} }
} }
for _, host := range strings.Split(server.Config.Host, " ") { 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)) address := net.JoinHostPort(host, strconv.Itoa(server.Config.Port))
if server.Config.UseSSL { if server.Config.UseSSL {
tlsCfg := &tls.Config{ tlsCfg := &tls.Config{

Loading…
Cancel
Save