I have a reverse proxy. Here I reverse proxy to api.example.com
and grpc.example.com:443
. My api
domain is working, but when I make a request to grpc.example.com:443
, grpc perceives it as grpc-web and sends a request as grpc.example.com:443/Hello.HelloService/Greeter
.
creds := credentials.NewTLS(&tls.Config{
InsecureSkipVerify: true,
})
opts := []grpc.DialOption{
grpc.WithTransportCredentials(creds),
grpc.WithBlock(),
}
conn, err := grpc.DialContext(context.Background(),
net.JoinHostPort("grpc.example.com", "443"), opts...)
if err != nil {
log.Fatalf("Could not connect to grpc: %v", err)
}
grpc reverse proxy:
grpcHeader := c.Request.Header.Get("Content-Type")
grpcserver := grpc.Server{}
if grpcHeader == "application/grpc" || grpcHeader == "application/grpc json" || grpcHeader == "application/grpc proto" {
grpcserver.ServeHTTP(c.Writer, c.Request)
}
CodePudding user response:
As per the comments gRPC generally runs over HTTP/2 (but there are other options).
The format of the HTTP/2 request path is "/" Service-Name "/" {method name}
. This means that seeing a request come in for grpc.example.com:443/Hello.HelloService/Greeter
is normal (and not an indication that gRPC-Web is in use).