Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GRPC reverse proxy confusing GRPC and GRPC-Web

Tags:

go

grpc

grpc-go

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)
    }
like image 890
NewCherryy Avatar asked Mar 14 '26 08:03

NewCherryy


1 Answers

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

like image 196
Brits Avatar answered Mar 17 '26 10:03

Brits



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!