reverse-proxy
reverse-proxy copied to clipboard
Feature request: Being able to determine if a request has matched a reverse proxy route in middleware
I have a middleware (outside of the reverse proxy world) that needs to do some stuff. I do not want to do this stuff if the current request is getting proxied. The only way I have found to reliably determine this is like this:
app.Use(async (context, next) =>
{
// Is there a better way of determining if the current request is a reverse proxy endpoint?
var isReverseProxyEndpoint = context.GetEndpoint()?.Metadata.OfType<RouteModel>().Any() == true;
if (isReverseProxyEndpoint) { await next(); return; } // Skip
I feel slightly not at ease doing it this way. Not sure if it's correct or if things might break in upcoming versions.
Kind regards, Emil
Edit: This does not work for MapForwarder(...)
That's correct, though I can understand it's ugly. There's no expectation it will break in the future.
MapForwarder won't have any special markers because it's a regular routing endpoint that calls the IHttpForwarder directly. You'd have to check the endpoint.DisplayName.
Triage: we could in theory explore making this nicer, but it doesn't seem like a common use case (we have heard no other requests for it) so we'll backlog it for now. The improvement would be to add an extension method on HttpContext that does the lookup described above.
If you are interested in this feature, let us know on this issue.
Hey! Sorry for the late response. I would agree that it is not a common use case, and I actually ended up with a different solution entirely.
Regards, Emil