gpt4 book ai didi

azure - 检查 Azure API 管理中的 Traceparent http header 的正确性

转载 作者:行者123 更新时间:2023-12-03 01:00:48 25 4
gpt4 key购买 nike

有没有办法检查 traceparent 的正确性在转发到后端服务之前使用 Azure API 管理策略的 http header ?

最佳答案

我能找到的最好方法是使用正则表达式创建 API 管理策略。它将发现大多数无效案例,除了一些极端案例。如果提供了无效的 http traceparent header ,则返回 400 - 错误请求,返回响应。

    <choose>
<when condition="@(!Regex.IsMatch(context.Request.Headers.GetValueOrDefault("traceparent",""), @"^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})$", RegexOptions.IgnoreCase, TimeSpan.FromMilliseconds(500)))">
<return-response>
<set-status code="400" reason="Bad request - Missing or invalid traceparent http header" />
<set-header name="Content-Type" exists-action="override">
<value>application/json</value>
</set-header>
<set-body>@(new JObject(new JProperty("statusCode", 400), new JProperty("message", "Missing or invalid &apos;traceparent&apos; http header for distributed tracing. More information how to supply one at https://www.w3.org/TR/trace-context-1/")).ToString())</set-body>
</return-response>
</when>
</choose>

关于azure - 检查 Azure API 管理中的 Traceparent http header 的正确性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60702962/

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