gpt4 book ai didi

node.js - 如何从 ApiGateway 缓存资源获取内容编码

转载 作者:行者123 更新时间:2023-12-03 07:42:42 30 4
gpt4 key购买 nike

我们有一个返回 gzip 编码的端点。我们想要缓存该值,我们正在使用 ApiGateway 来为我们做到这一点。资源方法定义如下,

GetManifestApiGatewayMethod: # very good
Type: "AWS::ApiGateway::Method"
Properties:
AuthorizationType: "NONE"
HttpMethod: "GET"
ResourceId:
Ref: ManifestConfigurationResource
RestApiId:
Ref: ApiGatewayRestApi
RequestParameters:
method.request.path.seasonCode: true
method.request.path.facilityCode: true
method.request.path.configurationCode: true
method.request.querystring.policyCode: true
method.request.header.PAC-Authorization: true
method.request.header.PAC-Application-ID: true
method.request.header.PAC-API-Key: true
method.request.header.PAC-Channel-Code: true
method.request.header.PAC-Organization-ID: true
method.request.header.PAC-Developer-ID: true
method.request.header.PAC-Request-ID: false
method.request.header.Accept-Encoding: true
MethodResponses:
- StatusCode: 200
# ResponseParameters:
# method.response.header.Content-Encoding: true
Integration:
IntegrationHttpMethod: GET
Type: HTTP
Uri: https://${self:provider.environment.PDI_HOST}/pdi/v1/manifest/{seasonCode}/{facilityCode}/{configurationCode}
PassthroughBehavior: WHEN_NO_MATCH
CacheKeyParameters:
- method.request.path.seasonCode
- method.request.path.facilityCode
- method.request.path.configurationCode
- method.request.querystring.policyCode
IntegrationResponses:
- StatusCode: 200
SelectionPattern: '\d\d\d'
# ResponseParameters:
# method.response.header.content-encoding: integration.response.body.headers.content-encoding
RequestParameters:
integration.request.path.seasonCode: method.request.path.seasonCode
integration.request.path.facilityCode: method.request.path.facilityCode
integration.request.path.configurationCode: method.request.path.configurationCode
integration.request.querystring.policyCode: method.request.querystring.policyCode
integration.request.header.Authorization: method.request.header.PAC-Authorization
integration.request.header.PAC-Application-ID: method.request.header.PAC-Application-ID
integration.request.header.PAC-API-Key: method.request.header.PAC-API-Key
integration.request.header.PAC-Channel-Code: method.request.header.PAC-Channel-Code
integration.request.header.PAC-Organization-ID: method.request.header.PAC-Organization-ID
integration.request.header.PAC-Developer-ID: method.request.header.PAC-Developer-ID
integration.request.header.PAC-Request-ID: method.request.header.PAC-Request-ID
integration.request.header.Accept-Encoding: method.request.header.Accept-Encoding

http.get方法中有以下逻辑:

const 编码 = response.headers["内容编码"];
if (encoding && encoding.indexOf("gzip") >= 0) {...}//处理 gzip

但是当我们使用上面的集成方法时,我没有得到通常通过直接访问它代理的 api 获得的 header 。我尝试传递一些带注释的代码,但在使用这些响应映射时出现内部服务器错误

最佳答案

从代码模板的外观来看,方法响应 header 看起来是正确的。

method.response.header.Content-Encoding: true

但是您的集成响应,ResponseParameters 似乎是错误的。

method.response.header.content-encoding: integration.response.body.headers.content-encoding

首先,属性Key应该完全匹配,因此大写可能会增加问题。然而,您的值(value)似乎才是真正的问题。根据AWS Documentation :

Use the destination as the key and the source as the value:

The destination must be an existing response parameter in theMethodResponse property.

The source must be an existing method request parameter or a staticvalue. You must enclose static values in single quotation marks andpre-encode these values based on the destination specified in therequest.

您似乎正在尝试将集成响应方法映射到该值,而不是方法请求参数

关于node.js - 如何从 ApiGateway 缓存资源获取内容编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62335666/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com