首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何通过http to grpc转码端点下载.zip文件?

如何通过http to grpc转码端点下载.zip文件?
EN

Stack Overflow用户
提问于 2021-03-13 20:10:36
回答 2查看 210关注 0票数 0

我将grpc端点定义如下。grpc端点返回一个.zip文件。它在grpc通道上工作正常,但在REST端点上下载它时遇到了问题。

我使用envoy来做http代码转换。

我现在的问题是,在REST端点上,下载响应头总是设置为application/json,而不是application/zip,这样zip下载才能正常工作。

你知道如何在转码过程中指示特使设置合适的头部,这样REST下载才能正常工作吗?

代码语言:javascript
运行
复制
  // Download build
  //
  // Download build
  rpc DownloadBuild(DownloadBuildRequest) returns (stream DownloadResponse) {
    option (google.api.http) = {
      get : "/v4/projects/{projectId}/types/{buildType}/builds/{buildVersion}/.download"
      headers: {}
    };
    option (grpc.gateway.protoc_gen_swagger.options.openapiv2_operation) = {
      description: "Download build.";
      summary: "Download build.";
      tags: "Builds";
      produces: "application/zip";
      responses: {
        key: "200"
        value: {
          description: "Download build";
        }
      }
      responses: {
        key: "401"
        value: {
          description: "Request could not be authorized";
        }
      }
      responses: {
        key: "404"
        value: {
          description: "Build not found";
        }
      }
      responses: {
        key: "500"
        value: {
          description: "Internal server error";
        }
      }
    };
  }
EN

回答 2

Stack Overflow用户

发布于 2021-03-15 21:39:02

好了,我已经找到了部分解决问题的方法。基本上,我必须使用google.api.HttpBody作为响应,并在其中设置内容类型。https://github.com/googleapis/googleapis/blob/master/google/api/httpbody.proto

https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_filters/grpc_json_transcoder_filter#sending-arbitrary-content

我仍然有一个问题,设置下载的文件名和扩展头。

票数 0
EN

Stack Overflow用户

发布于 2021-03-17 01:34:44

为了设置文件名头,我必须定义一个服务器拦截器,类似于这里提到的:

How to pass data from grpc rpc call to server interceptor in java

代码语言:javascript
运行
复制
  private class TrailerCall<ReqT, RespT> extends SimpleForwardingServerCall<ReqT, RespT> {

    public TrailerCall(final ServerCall<ReqT, RespT> delegate) {
        super(delegate);
    }
    
    @Override
    public void sendHeaders(Metadata headers) {
        headers.merge(RESPONSE_HEADERS_HOLDER_KEY.get());
        super.sendHeaders(headers);
    }

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66613339

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档