dotnet / dotnet/yarp

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

Open
#2,164 3 comments 0 reactions 0 assignees View on GitHub
Type: Enhancement
Dominant language
C#
Stars
9.6k
Forks
933
Avg merge
12d 18h
Merged PRs (30d)
2

Description

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.