Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Being able to determine if a request has matched a reverse proxy route in middleware #2164

Open
emilmuller opened this issue Jun 21, 2023 · 3 comments
Labels
Type: Enhancement New feature or request
Milestone

Comments

@emilmuller
Copy link

emilmuller commented Jun 21, 2023

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(...)

@emilmuller emilmuller added the Type: Idea This issue is a high-level idea for discussion. label Jun 21, 2023
@emilmuller emilmuller changed the title Feature request: Being able to determine if a request has matched a route in middleware Feature request: Being able to determine if a request has matched a reverse proxy route in middleware Jun 21, 2023
@Tratcher
Copy link
Member

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.

@adityamandaleeka
Copy link
Member

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.

@adityamandaleeka adityamandaleeka added this to the Backlog milestone Jul 11, 2023
@adityamandaleeka adityamandaleeka added Type: Enhancement New feature or request and removed Type: Idea This issue is a high-level idea for discussion. labels Jul 11, 2023
@emilmuller
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants