-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Allow to define HTTP filters with custom methods similar to controller definition #8179
Comments
Are you proposing to support |
What would happen for methods using imperative programming? @RequestFilter
public void loggingRequestFilter(HttpRequest<?> request) { Will Micronaut Framework execute these methods in the netty event pool? |
I assume we will create a list of filter composed by old fashion filters (classes annotated with |
Could not we do this for 3.9.0 or 3.10.0 ? Do we need Micronaut Framework 4.0 for this feature? |
Probably yes, but internally there is going to be another filter abstraction that can avoid reactive code.
Yes, just like it's now.
To properly implement ordering, we would need to have two sets of filters, request and response, and combining it with the original
I want to combine it with a refactoring of the HTTP processing so it would be better to target 4.0. |
re: "wraparound filters": we could offer a blocking alternative to wraparound filters as well: @ExecuteOn(BLOCKING)
HttpResponse filter(request, chain) {
// do some work before
HttpResponse response = chain.proceed(request);
// do some work after
return response;
} This is a good use case for loom. |
I think we need to keep classes annotated with |
I think this would be a mistake because of the number of edge cases will be high and it will likely add latency to the server. It's also more difficult to reason about what is possible given there is no API and it's up to the user to read the documentation to understand what is possible and/or trial and error. This will require a lot of compile time validation to ensure the arguments and return type are compatible. What happens when a String argument is present? Do we support @QueryValue and the such? What happens when a String is returned? You could create an imperative version of filters pretty easily and make the functionality easy to understand with a normal API |
My original idea was to support more argument binding and path filtering but I think that would have been overkill, the only supported arguments and return values would be the request/response. The implementation should be simple.
We have the same approach as the controllers, so it should be easy to understand.
We want to support using imperative return types and Reactive-Streams, Java Flow, Java Futures, Kotlin Coroutines. It's not possible to create one API, the approach is the same as with controllers and should be well understood, RESTEasy implements it in the same way. |
as part of this I would like to see a way we could simplify mutating the incoming body and outgoing body from a filter since that is not easy to do compared to say JAX-RS which has MessageBodyReader and MessageBodyWriter interfaces that are well understood. |
@yawkat @dstepanov can this be closed? |
Feature description
It would be nice to remove the requirement to always write reactive HTTP filters in Micronaut 4.
The requirements would be the ability to write a filter method using imperative, reactive (reactive-streams), Java 15 Flow, Kotlin coroutines, and completable future, just like it's possible to define a controller method.
The proposal to introduce two annotations:
@RequestFilter
- method can accept aHttpRequest
(possible mutable depending on Server/Client), and it can mutate its state or return a different instance. The method can return reactive type.Alternative to writing:
@ResponseFilter
- method can accept an originating request, aHttpResponse
(possible mutable depending on Server/Client), and it can mutate its state or return a different instance. The method can return reactive type.Alternative to writing:
Examples:
One HTTP filter would be able to contain multiple methods.
The open question is if we will support further filtering of the filter methods by annotating by
@Get, @Post
etc.WDYT @micronaut-projects/core-developers
The text was updated successfully, but these errors were encountered: