diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f21db18..61004587 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed +- added default port for creating a xresolver connection [#499](https://github.com/xmidt-org/webpa-common/pull/499) + ### Changed - Update word from blacklist to denylist. [#495](https://github.com/xmidt-org/webpa-common/pull/495) - Update references to the main branch. [#497](https://github.com/xmidt-org/webpa-common/pull/497) diff --git a/xresolver/xresolver.go b/xresolver/xresolver.go index 7d0f5ad4..9358ae4b 100644 --- a/xresolver/xresolver.go +++ b/xresolver/xresolver.go @@ -99,7 +99,7 @@ func (resolve *resolver) DialContext(ctx context.Context, network, addr string) return con, err } - log.WithPrefix(resolve.logger, level.Key(), level.DebugValue()).Log(logging.MessageKey(), "failed to create connection with other routes using original address", "addr", addr) + log.WithPrefix(resolve.logger, level.Key(), level.DebugValue()).Log(logging.MessageKey(), "failed to create connection with other routes using original address", "addr", addr, logging.ErrorKey(), err) // if no connection, create using the default dialer return resolve.dialer.DialContext(ctx, network, addr) } @@ -109,6 +109,15 @@ func (resolve *resolver) createConnection(routes []Route, network, port string) portUsed := port if route.Port != 0 { portUsed = strconv.Itoa(route.Port) + } else { + if route.Scheme == "http" { + portUsed = "80" + } else if route.Scheme == "https" { + portUsed = "443" + } else { + log.WithPrefix(resolve.logger, level.Key(), level.ErrorValue()).Log(logging.MessageKey(), "unknown default port", "scheme", route.Scheme, "host", route.Host) + continue + } } con, err := resolve.dialer.Dial(network, net.JoinHostPort(route.Host, portUsed)) if err == nil {