node.js - 如何从 ApiGateway 缓存资源中获取内容编码
问题描述
我们有一个返回 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 encoding = response.headers["content-encoding"];
if (encoding && encoding.indexOf("gzip") >= 0) {...} // handle the gzip
但是当我们使用上面的集成方法时,我没有得到通常直接点击它代理的 api 得到的标题。有一些注释代码,我试图将其传递,但internal server error
是当使用这些响应映射时我得到了。
解决方案
从您的代码模板的外观来看,方法响应标头看起来是正确的。
method.response.header.Content-Encoding: true
但是,您的集成响应 ResponseParameters 似乎是错误的。
method.response.header.content-encoding: integration.response.body.headers.content-encoding
首先,属性Key应该完全匹配,因此大写可能会增加问题。但是,您的价值看起来是真正的问题。根据AWS 文档:
使用目标作为键,源作为值:
目标必须是 MethodResponse 属性中的现有响应参数。
源必须是现有方法请求参数或静态值。您必须将静态值括在单引号中,并根据请求中指定的目标对这些值进行预编码。
看起来好像您正在尝试将集成响应方法映射到值而不是方法请求参数。
推荐阅读
- python - 如何在不使用 Sequential() 的情况下在 Keras 中堆叠图层?
- ruby-on-rails - 如何在用户机器上创建文件而不是在服务器中创建然后使用 rails 下载
- windows-10 - Unable to Update the SCCM Consol
- angular - import * as someName from '@angular/core' in angular 2/4/5/6/latter 版本
- ios - 在两个纬度和经度之间绘制折线
- sbt - 从 ScalaJs 调用旋转模板
- javascript - 为什么html音频自动播放不起作用
- excel - 复制值并排除 #N/A 单元格
- excel - 如何在 Excel 中计算“客户月数”
- bash - 更改终端窗口背景颜色和文本