swagger - 如何在 http 转码的 zip 内容响应上设置标头?
问题描述
我有一个下载 zip 文件 grpc 服务,我正在使用 envoy 转码为 http。proto 文件服务定义如下所示:
// 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"
headers: []
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";
}
}
};
}
我从一个招摇的 UI 调用这个端点。我可以看到(网络选项卡)支持的内容返回了 *MB 的内容,然后它停止了,但招摇的 UI 继续加载。我还可以在 java GRPC 代码中看到请求已完成。但招摇的 UI 仍然显示加载 gif。
Request URL: http://localhost:51053/v4/projects/1/types/NLU/builds/1/.download
Request Method: GET
Status Code: 200 OK
Remote Address: [::1]:51053
Referrer Policy: no-referrer-when-downgrade
[Response Headers]
content-type: application/json
date: Thu, 11 Mar 2021 20:36:06 GMT
grpc-accept-encoding: gzip
grpc-encoding: identity
server: envoy
transfer-encoding: chunked
x-envoy-upstream-service-time: 15925
[Request headers]
accept: application/zip
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9,fr;q=0.8,ro;q=0.7,pl;q=0.6
Authorization: mix-api-client:4cbab4f8-2773-432f-9376-49424c24ded5
Cache-Control: no-cache
Connection: keep-alive
查看浏览器端的响应,可以看到响应内容类型标头设置为 json 而不是 zip。
所以我想这是我的问题。
现在我尝试在 http API 响应级别定义内容类型标头,但到目前为止还没有运气。
当我尝试编译带有 headers 字段的 proto 文件时,我不断收到如下错误。
Error while parsing option value for "http": Message type "google.api.HttpRule" has no field named "headers".
知道如何在 http 转码 API 级别设置 application/zip 标头吗?
谢谢
解决方案
推荐阅读
- java - 剩余参数的计数
- authentication - 如何使用 supbase.io 实现匿名授权?
- ios - 如何记录视图加载所需的时间
- typescript - 在 Typescript 中,如何在初始化后将类型化值转换为文字值?
- javascript - VS 代码,没有使用 javascript 的自动完成功能 (discord.js)
- python - python - 如何以最有效的方式完成这个特殊的求和
- azure - 如何更改 Azure 中 VMSS 的分析工作区?
- python-3.x - Tkinter 按钮需要在同一个网格中创建多次,但不需要,我如何让它做到这一点?
- elasticsearch - 微服务:与多个实例的服务间通信
- swift - 修改swiftui数组值