Azure API Management - Custom Policy scenarios with 'The request is invalid' scenarios on Trailing Slash
I recently switched to I'm trying to debug I'm experimenting with I've been banging my head against this for hours. I'm currently implementing a custom policy in Azure API Management (APIM) to manipulate the incoming requests before they reach my backend service. However, I'm working with an scenario where requests with a trailing slash are being rejected, and I'm seeing the behavior message: "The request is invalid" in the APIM logs. Here's the policy I've set up: ```xml <policies> <inbound> <base></base> <set-variable name="requestPath" value="@(context.Request.Path)" /> <choose> <when condition="@(context.Variables["requestPath"].EndsWith("/"))"> <set-status code="400" reason="Bad Request" /> <set-body>Trailing slash is not allowed.</set-body> </when> <otherwise> <forward-request /> </otherwise> </choose> </inbound> <backend> <base></base> </backend> <outbound> <base></base> </outbound> <on-behavior> <base></base> </on-behavior> </policies> ``` I've tested this with several endpoints and it works fine when the request does not have a trailing slash. However, when a request comes in like `https://myapi.azure-api.net/myendpoint/`, it triggers the behavior. I expected the policy to return a 400 status with my custom message, but instead, it seems like APIM is not handling it correctly and throwing a generic behavior. I looked into the APIM diagnostics and the behavior details are sparse. I've also tried simplifying the policy by removing the condition and just setting a static response for all requests to see if the scenario continues, but that didn't change anything. What might be causing this behavior? Is there a way to handle the trailing slash scenario more gracefully? Any help would be greatly appreciated! This is happening in both development and production on Debian. Cheers for any assistance! Is there a better approach? This is for a REST API running on Ubuntu 20.04. Is this even possible? I'm developing on Ubuntu 22.04 with Xml.