Skip to content

Commit

Permalink
adding default port for creating a xresolver connection (#499)
Browse files Browse the repository at this point in the history
* adding default port for creating a xresolver con

* updated changelog
  • Loading branch information
kcajmagic authored Jul 20, 2020
1 parent f82f65f commit 4566ed9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 10 additions & 1 deletion xresolver/xresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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 {
Expand Down

0 comments on commit 4566ed9

Please sign in to comment.