英文:
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
服务器变量。您可以使用偏移量仅获取该值,并将其返回在预定义的响应头中。此示例规则集适用于您的示例:
如果您想要动态解析查询字符串字段并将其放入 '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:
Query url string from a Chrome Incognito window:
Result in Chrome Developer Tools:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论