英文:
GRPC reverse proxy confusing GRPC and GRPC-Web
问题
我有一个反向代理。在这里,我将反向代理到 api.example.com
和 grpc.example.com:443
。我的 api
域名可以正常工作,但是当我向 grpc.example.com:443
发送请求时,grpc 将其视为 grpc-web,并将请求发送到 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 反向代理:
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)
}
英文:
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)
}
答案1
得分: 1
根据评论,gRPC通常在HTTP/2上运行(但也有其他选项)。
HTTP/2请求路径的格式是"/" Service-Name "/" {method name}
。这意味着看到一个请求grpc.example.com:443/Hello.HelloService/Greeter
是正常的(并不表示正在使用gRPC-Web)。
英文:
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).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论