在 API Gateway 集成请求的设置中,可以将 Content-Type 映射为 text/plain。在这种情况下,最好将映射值设置为字符串 "*",以确保 AWS API Gateway 不会将 Content-Type 转换为其他 MIME 类型。以下是示例代码:
const integration = new apigateway.MockIntegration({
requestTemplates: {
'application/json': '{\n "statusCode": 200\n}'
},
integrationResponses: [
{
statusCode: "200",
responseTemplates: {
'text/plain': '$input.path("$.mockResponse")'
},
responseParameters: {
'method.response.header.Content-Type': "'text/plain'"
}
}
],
passthroughBehavior: apigateway.PassthroughBehavior.NEVER,
requestParameters: {}
});
const method = api.root.addResource('test').addMethod('GET', integration);
method.methodResponses.push({
statusCode: '200',
responseParameters: {
'method.response.header.Content-Type': true,
},
responseModels: {
'text/plain': new apigateway.EmptyModel()
}
});