Skip to content

Commit 097d050

Browse files
committed
Incorporated review comments
1 parent a4bc7d3 commit 097d050

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

examples/Replay request on error.policy.xml

+21-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<!--
2-
This policy sample demonstrates a pattern of replaying the request.
3-
For eg: One scenario could be when we are using quota and rate limit policies,for some special tier consumers,
4-
we would still like to serve the request if there was a quota error but this time with a low-end backend.
5-
6-
The "example-policy-name" string is in the when condition is just for example and needs to be replaced with the actual policy name accordingly.
2+
This policy sample demonstrates a pattern of replaying a request.
3+
For eg: one scenario could be when we are using quota and rate limit policies and for some special tier consumers,
4+
we would like to serve the request even if there was a quota error but with a different backend.
5+
In such cases, we can replay the request to a different backend with the same request headers and body.
6+
The "example-policy-name" string in the when condition is just for example and needs to be replaced with the actual policy name accordingly.
77
88
Important Note:
9-
Although this pattern works, we would do end up having 2 log entries now for the same request, since the request is now being replayed.
9+
Although this pattern works, an important point to note here is since we are now replaying the request
10+
we would end up having 2 log entries for the same request in the APIM logs.
1011
-->
1112
<policies>
1213
<inbound>
@@ -25,18 +26,28 @@
2526
<set-variable name="replay-url" value="@("http://" + context.Request.Headers.GetValueOrDefault("X-Original-Host") + context.Request.Headers.GetValueOrDefault("X-Original-Url"))" />
2627
<set-variable name="original-error-source" value="@(context.LastError.Source)" />
2728
<set-variable name="original-error-reason" value="@(context.LastError.Reason)" />
28-
<!-- We replay the same request again to APIM -->
29+
30+
<!-- Following snipped demonstrates the replya pattern,
31+
For this, we are using send request's "copy" mode which would copy the original request's headers and body accoridngly.
32+
Policy Documentation link https://learn.microsoft.com/en-us/azure/api-management/send-request-policy#attributes
33+
-->
34+
<!-- Note:
35+
As per the policy documentation, the send request method will copy the request headers and body accordingly
36+
but we should always validate this and we can expclitly set the the request body and headers as needed.
37+
-->
2938
<send-request mode="copy" response-variable-name="replay-response" timeout="60" ignore-error="false">
3039
<set-url>@(context.Variables.GetValueOrDefault<string>("replay-url"))</set-url>
31-
<set-method>POST</set-method>
3240
<!-- While replaying the request this time, we might need to pass some additional information
3341
this time in our request with corresponding logic in the inbound section to process such requests
34-
The string "skip-example-policy-error" here is just as an example -->
42+
The string "skip-example-policy-error" here is just an example of additional header we are sending here
43+
-->
3544
<set-header name="skip-example-policy-error" exists-action="override">
3645
<value>true</value>
3746
</set-header>
3847
</send-request>
39-
<!-- THIS IS AN IMPORTANT STEP i.e. the response captured in policy variable "response-variable-name" defined above has to be explicity sent back -->
48+
<!-- THIS IS AN IMPORTANT STEP i.e. the response captured in the send-request policy attribute
49+
"response-variable-name" defined above has to be explicity sent back
50+
-->
4051
<return-response response-variable-name="replay-response">
4152
<!-- Any additional headers like below can further be added as part of response tracking -->
4253
<set-header name="x-request-replayed" exists-action="override">

0 commit comments

Comments
 (0)