Updating HttpContext.Request.Path inside middleware has no effect in selecting the endpoint for the request #49454
Labels
area-networking
Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
✔️ Resolution: Answered
Resolved because the question asked by the original author has been answered.
Status: Resolved
Is there an existing issue for this?
Describe the bug
As mentioned in issues such as this and this, Azure app service FE/proxy decodes the encoded parts of the request URL path. The recommendation is to use the
X-WAWS-Unencoded-URL
header value to get the un decoded/raw value.What is the right extensibility point in aspnet core pipeline to replace the current request path string value to the value of the above mentioned header, so that the routing module uses it and route it to the correct endpoint? The use case here is having a route parameter for which the value contains
%2F
(encoded version of/
) in it.and a request like this
api/departments/cloud%2Fdevdiv
This code works fine locally, but fails when deployed to app service.
I wrote a middleware which replaces the request path of httpcontext and registered as the very first middleware in the request processing pipeline, but that does not seems to work.
and
Is this not the right extensibility point to make this change?
AI logs of 2 requests, one resulted in 200 OK and the other is 404
Expected Behavior
Should be able to replace the request path value with the raw value received from header and the routing/endpoint selection should respect that during the same request processing. Not looking to return a redirect response.
Steps To Reproduce
Code shared in he issue description is enough to repro. To validate locally, you may also try to replace the path value with the route to a different endpoint like below.
Here, the expected behavior is that, the
/api/products
request to be invoking the code from the endpoint with/api/tags
route decoration.Exceptions (if any)
No response
.NET Version
net6.0
Anything else?
No response
The text was updated successfully, but these errors were encountered: