From 804aa5d21a44efaeb181ba7fec59f3801eca5f07 Mon Sep 17 00:00:00 2001 From: Shingo Omura Date: Tue, 14 Jul 2020 23:36:22 +0900 Subject: [PATCH] setting host part of address as :authority pseudo header. 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 --- client/client.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/client/client.go b/client/client.go index 7a5282f6..96fb5c29 100644 --- a/client/client.go +++ b/client/client.go @@ -6,6 +6,7 @@ import ( "crypto/x509" "io/ioutil" "net" + "net/url" grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware" "github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc" @@ -71,6 +72,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)