Google端点+ grpc-web

时间:2019-01-15 14:08:23

标签: 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端点回来的,这导致人们认为grpc-web支持可能尚未完全存在。

有人设法做到这一点吗?

1 个答案:

答案 0 :(得分:1)

事实证明,问题中链接的关于拉取请求的对话显示了(并且稍后由我进行了测试),问题是我试图使用Google Cloud终结点不支持的grpc-web-text协议

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