正如 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 支持可能还没有完全存在。
有没有人设法让这个工作?