Skip to content

Commit

Permalink
chore(client): move tcp scheme removal logic
Browse files Browse the repository at this point in the history
Signed-off-by: Höhl, Lukas <[email protected]>
  • Loading branch information
Höhl, Lukas committed Aug 9, 2023
1 parent 842a5fc commit 379a405
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"crypto/tls"
"crypto/x509"
"fmt"
"net"
"net/url"
"os"
Expand Down Expand Up @@ -117,18 +116,14 @@ func New(ctx context.Context, address string, opts ...ClientOpt) (*Client, error
if dialFn != nil {
gopts = append(gopts, grpc.WithContextDialer(dialFn))
}
addressParts := strings.SplitN(address, "://", 2)
if len(addressParts) != 2 {
return nil, fmt.Errorf("%s is missing scheme", address)
}
if addressParts[0] == "tcp" {
// remove tcp scheme from address, since default dialer doesn't expect that
address = addressParts[1]
}
}
if address == "" {
address = appdefaults.Address
}
uri, err := url.Parse(address)
if err != nil {
return nil, err
}

// Setting :authority pseudo header
// - HTTP/2 (RFC7540) defines :authority pseudo header includes
Expand All @@ -143,12 +138,13 @@ func New(ctx context.Context, address string, opts ...ClientOpt) (*Client, error
}
if authority == "" {
// authority as hostname from target address
uri, err := url.Parse(address)
if err != nil {
return nil, err
}
authority = uri.Host
}
if uri.Scheme == "tcp" {
// remove tcp scheme from address, since default dialer doesn't expect that
address = uri.Host
}

gopts = append(gopts, grpc.WithAuthority(authority))

unary = append(unary, grpcerrors.UnaryClientInterceptor)
Expand Down

0 comments on commit 379a405

Please sign in to comment.