Merge pull request #1567 from everpeace/fix-authority-header

Setting `Host` part  of address url to `:authority` pseudo header
v0.8
Tõnis Tiigi 2020-08-06 15:43:00 -07:00 committed by GitHub
commit 279d686fec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 0 deletions

View File

@ -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)