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

Enable request transforms to reject requests #1923

Merged
merged 5 commits into from
Nov 14, 2022

Conversation

Tratcher
Copy link
Member

@Tratcher Tratcher commented Nov 5, 2022

Fixes #1701 @leastprivilege

If a request transform encounters a problem right now the only thing it can do is throw. A few customers have asked how to generate a response and exit gracefully. Response transforms can already do this by returning false to prevent us from proxying the body.

HttpTransformer.TransformRequestAsync has a signature that can't return any additional information without an API breaking change. Instead, we can detect if a transform generated a response by checking HttpResponse.StatusCode or HasStarted. In this case we'll stop trying to proxy the request and exit gracefully. If someone had modified the StatusCode before this change it would have been overwritten when proxying the response. If they had started the response it would have failed when trying to proxy the response later.

There's a series of related requests that I checked if could be solved in the same way but decided against it. I think these can be handled at the config and routing layer with alternate endpoints, there's no need for them to execute the proxy pipeline / load balancing, session affinity, etc. I'll send a separate PR for those.

TODO: Update docs

@Tratcher Tratcher added this to the YARP 2.0.0 milestone Nov 5, 2022
@Tratcher Tratcher self-assigned this Nov 5, 2022
src/ReverseProxy/Forwarder/HttpForwarder.cs Outdated Show resolved Hide resolved
@Tratcher Tratcher enabled auto-merge (squash) November 14, 2022 23:00
@Tratcher Tratcher merged commit c39fcf8 into main Nov 14, 2022
@Tratcher Tratcher deleted the tratcher/requesttransformresponds branch November 14, 2022 23:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Request/response validators
3 participants