使用HTTP代理访问AWS API Gateway中的cloudfront-viewer-country标头? [英] Accessing cloudfront-viewer-country header in AWS API Gateway using HTTP Proxy?

查看:54
本文介绍了使用HTTP代理访问AWS API Gateway中的cloudfront-viewer-country标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用AWS API Gateway及其HTTP代理.

I'm using AWS API Gateway and its HTTP Proxy.

我需要将 CloudFront-Viewer-Country 标头传递给我的端点.我尝试遵循以下问题中概述的相同设置使用HTTP代理访问AWS API Gateway中的标头?

I need to pass the CloudFront-Viewer-Country header to my endpoint. I tried following the same setup outlined in the following question Access headers in AWS API Gateway using HTTP Proxy?

并且我在端点服务器上收到以下标头.

and I'm getting the following headers on my endpoint server.

Array
(
    [host] => example.com
    [Accept] => application/json
    [User-Agent] => AmazonAPIGateway_c8752844lh
    [x-amzn-apigateway-api-id] => c8752844lh
    [X-Amzn-Trace-Id] => Root=1-59bd7a5e-003ef07b3c4c3680299801f1
    [X-Forwarded-For] => xx.xxx.xx.xxx
    [X-Forwarded-Port] => 443
    [X-Forwarded-Proto] => https
    [Connection] => keep-alive

)

但是, CloudFront-Viewer-Country 不在其中.如果我使用lambda函数而不是HTTP代理,则可以看到更多的标头(包括 CloudFront-Viewer-Country ).

However, the CloudFront-Viewer-Country is not among them. If I used a lambda function instead of HTTP Proxy, I can see a lot more headers (including the CloudFront-Viewer-Country).

任何人都可以告诉我如何使用HTTP代理访问端点上所需的标头吗?

Could anyone please tell me how to access the required header on my endpoint using HTTP Proxy ?

推荐答案

对于需要头的资源和方法,请转到方法请求"→"HTTP请求头"→添加头",然后将名称设置为 CloudFront-Viewer-国家.单击带圆圈的选中标记添加.这会将标头暴露给执行流程的其余部分.

For the resource and method where you want the header, go to Method Request → HTTP Request Headers → Add Header and set the Name as CloudFront-Viewer-Country. Click the circled checkmark to add. This exposed the header to the remainder of the execution flow.

然后,在集成请求"→"HTTP标头"→添加标头"中.

Then, in Integration Request → HTTP Headers → Add Header.

将名称设置为 CloudFront-Viewer-Country 并设置从 method.request.header.CloudFront-Viewer-Country 映射,然后单击带圆圈的对勾以添加.这将拾取公开的标头,并将其添加到转发到后端的请求中.

Set the Name to CloudFront-Viewer-Country and set Mapped from method.request.header.CloudFront-Viewer-Country and click the circled checkmark to add. This picks up the exposed header and adds it to the request that is forwarded to your back-end.

部署API.

这篇关于使用HTTP代理访问AWS API Gateway中的cloudfront-viewer-country标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆