Skip to content

Commit

Permalink
Fix --destination flag precedence
Browse files Browse the repository at this point in the history
  • Loading branch information
Bradley Kemp committed Jun 18, 2019
1 parent 6a7e66d commit 147eef4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## [v0.1.2](https://github.com/bradleyjkemp/grpc-tools/releases/tag/v0.1.2)
* Fixed bug where the `--destination` flag didn't work (issue [#13](https://github.com/bradleyjkemp/grpc-tools/issues/13))

## [v0.1.1](https://github.com/bradleyjkemp/grpc-tools/releases/tag/v0.1.1)
* Added automatic detection of mkcert certificates in the current directory

Expand Down
10 changes: 7 additions & 3 deletions grpc-proxy/grpc_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,16 @@ func (s *server) proxyHandler(srv interface{}, ss grpc.ServerStream) error {
authority := md.Get(":authority")
var destinationAddr string
switch {
case s.destination != "":
// used hardcoded destination if set (used by clients not supporting HTTP proxies)
destinationAddr = s.destination

case len(authority) > 0:
// use authority from request
// TODO: verify that this destination doesn't resolve to the proxy itself
// to avoid an infinite proxy loop
destinationAddr = authority[0]
case s.destination != "":
// fallback to hardcoded destination (used by clients not supporting HTTP proxies)
destinationAddr = s.destination

default:
// no destination can be determined so just error
return status.Error(codes.Unimplemented, "no proxy destination configured")
Expand Down

0 comments on commit 147eef4

Please sign in to comment.