Skip to content

Commit

Permalink
setting host part of address as :authority pseudo header.
Browse files Browse the repository at this point in the history
grpc-go uses a slightly different naming scheme(https://github.com/grpc/grpc/blob/master/doc/naming.md)
This will end up setting rfc non-complient :authority header to address string (e.g. tcp://127.0.0.1:1234).
So, this commit changes to sets right authority header via WithAuthority DialOption.

Signed-off-by: Shingo Omura <everpeace@gmail.com>
  • Loading branch information
everpeace committed Jul 14, 2020
1 parent 721eb7e commit 9c40be7
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"crypto/x509"
"io/ioutil"
"net"
"net/url"
"time"

grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
Expand Down Expand Up @@ -74,6 +75,15 @@ func New(ctx context.Context, address string, opts ...ClientOpt) (*Client, error
address = appdefaults.Address
}

// grpc-go uses a slightly different naming scheme: https://github.com/grpc/grpc/blob/master/doc/naming.md
// This will end up setting rfc non-complient :authority header to address string (e.g. tcp://127.0.0.1:1234).
// So, here sets right authority header via WithAuthority DialOption.
addressUrl, err := url.Parse(address)
if err != nil {
return nil, err
}
gopts = append(gopts, grpc.WithAuthority(addressUrl.Host))

unary = append(unary, grpcerrors.UnaryClientInterceptor)
stream = append(stream, grpcerrors.StreamClientInterceptor)

Expand Down Expand Up @@ -192,5 +202,5 @@ func resolveDialer(address string) (func(string, time.Duration) (net.Conn, error
return f, nil
}
// basic dialer
return dialer, nil
return nil, nil
}

0 comments on commit 9c40be7

Please sign in to comment.