gpt4 book ai didi

amazon-web-services - API Gateway 验证内容类型 header

转载 作者:行者123 更新时间:2023-12-04 08:04:15 25 4
gpt4 key购买 nike

如果内容类型不是 json api 网关不进行验证而只是通过。我使用代理集成,所以没有映射模板,只能使用“when_no_match”。我使用内联招摇。

我可以检查标题是否存在但不能检查值 - 我该怎么做?

/myMethod:
post:
x-amazon-apigateway-request-validator : "myvalidator"
parameters:
# How do I also validate Content-Type value is "application/json"
- name: Content-Type
in: header
required: true

我想要 API 网关来验证这一点,所以我不必在代码中检查它

最佳答案

转至 Integration Request端点的选项卡,单击 Mapping Templates , 设置 Request body passthroughnever , 为 application/javascript 添加映射模板,然后点击 Method Request PassthroughGenerate template 旁边的下拉菜单中.

这是招摇的片段:
requestTemplates:
application/json: |
## See http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html
## This template will pass through all parameters including path, querystring, header, stage variables, and context through to the integration endpoint via the body/payload
#set($allParams = $input.params())
{
"body-json" : $input.json('$'),
"params" : {
#foreach($type in $allParams.keySet())
#set($params = $allParams.get($type))
"$type" : {
#foreach($paramName in $params.keySet())
"$paramName" : "$util.escapeJavaScript($params.get($paramName))"
#if($foreach.hasNext),#end
#end
}
#if($foreach.hasNext),#end
#end
},
"stage-variables" : {
#foreach($key in $stageVariables.keySet())
"$key" : "$util.escapeJavaScript($stageVariables.get($key))"
#if($foreach.hasNext),#end
#end
},
"context" : {
"account-id" : "$context.identity.accountId",
"api-id" : "$context.apiId",
"api-key" : "$context.identity.apiKey",
"authorizer-principal-id" : "$context.authorizer.principalId",
"caller" : "$context.identity.caller",
"cognito-authentication-provider" : "$context.identity.cognitoAuthenticationProvider",
"cognito-authentication-type" : "$context.identity.cognitoAuthenticationType",
"cognito-identity-id" : "$context.identity.cognitoIdentityId",
"cognito-identity-pool-id" : "$context.identity.cognitoIdentityPoolId",
"http-method" : "$context.httpMethod",
"stage" : "$context.stage",
"source-ip" : "$context.identity.sourceIp",
"user" : "$context.identity.user",
"user-agent" : "$context.identity.userAgent",
"user-arn" : "$context.identity.userArn",
"request-id" : "$context.requestId",
"resource-id" : "$context.resourceId",
"resource-path" : "$context.resourcePath"
}
}
passthroughBehavior: "never"
httpMethod: "POST"
type: "aws"

关于amazon-web-services - API Gateway 验证内容类型 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52428479/

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