Enable request transforms to reject requests #1923
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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