google-cloud-platform - 谷歌端点 + grpc-web

标签 google-cloud-platform google-cloud-endpoints grpc grpc-web

如 Google 端点的 esp 代理的变更日志中所示 (https://github.com/cloudendpoints/esp/pull/283),已为其添加了对 grpc-web 的支持。

但是我无法让它工作。我使用以下 cors 配置部署了 esp

# Note: The following lines are included in a server block, so we cannot use all Nginx constructs here.
set $cors_expose_headers "";
set $cors_max_age "";

if ($request_method = 'OPTIONS') {
    set $cors_max_age 1728000;
    return 204;
}

if ($request_method = 'POST') {
    set $cors_expose_headers 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range,content-transfer-encoding,custom-header-1,x-accept-content-transfer-encoding,x-accept-response-streaming,x-user-agent,x-grpc-web,grpc-timeout';
}

if ($request_method = 'GET') {
    set $cors_expose_headers 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range,,content-transfer-encoding,custom-header-1,x-accept-content-transfer-encoding,x-accept-response-streaming,x-user-agent,x-grpc-web,grpc-timeout';
}

add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range,,content-transfer-encoding,custom-header-1,x-accept-content-transfer-encoding,x-accept-response-streaming,x-user-agent,x-grpc-web,grpc-timeout';
add_header 'Access-Control-Expose-Headers' $cors_expose_headers;
add_header 'Access-Control-Max-Age' $cors_max_age;

然后配置一个 GRPC Google 端点。

当我尝试向该端点发送 grpc-web 请求时,我可以看到 OPTIONS 请求通过了,但我在实际请求中得到了 400 返回,响应如下

{
 "code": 3,
 "message": "Unexpected token.\AAAAASIKAF5etnRlbkFw\n^",
 "details": [
  {
   "@type": "type.googleapis.com/google.rpc.DebugInfo",
   "stackEntries": [],
   "detail": "internal"
  }
 ]
}

我认为这是从 Google Endpoints 返回的结果,这导致人们相信 grpc-web 支持可能还不完全存在。

有没有人设法让它工作?

最佳答案

事实证明,正如问题中链接的拉取请求的对话所示(后来我也测试过),问题是我试图使用谷歌云端点不支持的 grpc-web-text 协议(protocol).

经过一些测试我可以确认谷歌云端点确实支持 grpc-web 但只支持二进制有线格式,这意味着不支持服务器流,只支持一元调用

关于google-cloud-platform - 谷歌端点 + grpc-web,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54200545/

相关文章:

java - 对象化 v5 : Profile is not a supported property type

java - 应用引擎 : call endpoints of another module on the same server

java - 通过 Google Cloud 上的 Ingress 公开 GRPC 服务器

java - GoogleCredential.getApplicationDefault() 不返回 GCE 实例凭证

google-cloud-platform - 如何删除我的谷歌云平台计费账户?

postgresql - Cloud Run 突然得到 `Improper path/cloudsql/{SQL_CONNECTION_NAME} to connect to Postgres Cloud SQL instance "{SQL_CONNECTION_NAME }"`

node.js - 使用服务帐户访问 Google Container 构建器日志 - 403 禁止错误

android - 如何将我的 Android 应用程序指向我的在线 apengine 端点

java - 发布构建失败

java - 如何使用 mockito 模拟 grpc ServiceBlockingStub 抛出 StatusRuntimeException(Status.UNAVAILABLE)?