Azure Frontdoor动态标头

huangapple go评论57阅读模式
英文:

Azure Frontdoor Dynamic Header

问题

我使用Azure Frontdoor并想检查查询字符串中是否有一个名为"paid"的键,如果存在,将其用于响应标头。

例如,如果请求进入https://example.com/?foo=bar,我希望返回一个使用此查询字符串值的标头,即X-Foo-Header: bar

这是否可行?

我注意到在响应标头操作中可以访问{query_string}服务器变量,但不确定Frontdoor是否支持对该值进行任何类型的动态检查。Ref: https://learn.microsoft.com/en-us/azure/frontdoor/rule-set-server-variables

英文:

I'm using Azure Frontdoor and want to inspect the querystring for a key paid, and if it is present, use it in an Response Header.

For example, if the request comes in to https://example.com/?foo=bar, I'd like to return a header that uses this querystring value, ie: X-Foo-Header: bar

Is this possible?

I note I can access the {query_string} server variable in the Response Header action, but am unsure if Frontdoor has support to enable any type of dynamic inspection of that value. Ref: https://learn.microsoft.com/en-us/azure/frontdoor/rule-set-server-variables

答案1

得分: 1

如果查询字符串中只有一个字段,并且您提前知道它,您可以使用 query_string 服务器变量。您可以使用偏移量仅获取该值,并将其返回在预定义的响应头中。此示例规则集适用于您的示例:

Azure Frontdoor动态标头

来自Chrome隐身窗口的查询URL字符串:
Azure Frontdoor动态标头

在Chrome开发者工具中的结果:
Azure Frontdoor动态标头

如果您想要动态解析查询字符串字段并将其放入 'X-something-Header',我认为目前不可能。您需要动态设置偏移量值,并能够解析查询字符串以确定 '=' 字符的位置。

英文:

If there is only one field in the query string and you know it ahead of time you can use the query_string server variable. You can use the offset to get only the value and return it in the predefined response header. This example rule set works for your example:

Azure Frontdoor动态标头

Query url string from a Chrome Incognito window:
Azure Frontdoor动态标头

Result in Chrome Developer Tools: Azure Frontdoor动态标头

If you're wanting it to parse the query string field dynamically into an 'X-something-Header' I don't believe it's possible right now. You'd have to dynamically set the offset value and be able to parse the query string to determine the position of the '=' character.

huangapple
  • 本文由 发表于 2023年5月17日 19:02:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/76271389.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定