-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Add support for setting response status and response headers support via annotations #20242
Conversation
This comment has been minimized.
This comment has been minimized.
...reactive/common-runtime/src/main/java/io/quarkus/resteasy/reactive/server/common/Header.java
Outdated
Show resolved
Hide resolved
...rc/test/java/io/quarkus/resteasy/reactive/server/test/responseheader/ResponseHeaderTest.java
Show resolved
Hide resolved
...rc/test/java/io/quarkus/resteasy/reactive/server/test/responsestatus/ResponseStatusTest.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for this!
I am personally in favor of this idea, but let's see what Stuart and Stephane say
@geoand I changed the logic according to your comments. For now, everything will work for Uni and Multi(I assume it's right if refer to the requirements), but I can add logic that was implemented the first time, and annotations will work for Response as well |
Thanks for the update! I would argue that the annotations should not work of the return type is |
...rc/test/java/io/quarkus/resteasy/reactive/server/test/responseheader/ResponseHeaderTest.java
Show resolved
Hide resolved
@@ -132,6 +133,9 @@ | |||
*/ | |||
private List<UriMatch> matchedURIs; | |||
|
|||
private Map<String, String> responseHeaders; | |||
private Integer responseStatus; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not to fond of adding new fields here to be honest...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we only have to change headers and statuses if everything is ok, I don't see a more elegant solution than passing them to the ResteasyReactiveRequestContext, and change them if successful
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand the rationale here, but I don't want to set the precedent of adding new fields for little gain.
Furthermore, by looking at the class, one would not really know when these fields are set, when it's safe to use them and when they actually affect the final result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In theory, I can add annotation checking to AsyncReturnTypeScanner and pass values to the handler, but this will spawn a chain of new fields though the life cycle of annotation will be more clear
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the fact that I completely certain that when I look at this code down the line I will not know when these fields are used, it's going to be a hard no to adding these. We should not have to add custom fields each time we add peripheral functionality.
Please consider alternatives.
@geoand can you take a look? I changed implementation a bit, removed additional fields from Context as you suggested, now it supports all return types, I also added additional tests for CompletionStage and plain return types |
1c65d6d
to
95ae237
Compare
Thanks. I'll have a look later on today or tomorrow. |
@@ -15,6 +15,7 @@ public void handle(ResteasyReactiveRequestContext requestContext) throws Excepti | |||
|
|||
result.handle((v, t) -> { | |||
if (t != null) { | |||
requestContext.serverResponse().clearResponseHeaders(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain why this (and similar calls in other places) is needed please?
Asking because it is not apparent why it's needed and it seems that it was added just to make something specific work.
Furthermore, this could have performance implications
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was added to clear custom headers in case of exceptions, but this doesn't clear standard headers like content-type and content-length. I think this will be useful even if there will be other implementations of custom headers in the future
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the same spirit as one of my previous comments, I don't like the fact that we need to make changes to unrelated areas just to support this feature.
I would have set the status and headers after the resource method was invoked thus eliminating the need to clear headers when an exception occurs.
Satisfying all the requirements I've set in the various comment might require more "infrastructure" than we currently have. To be honest, I didn't expect this to be picked up by a contributor :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's an unrelated area) But I got you, will think about another implementation, but for now I'll close this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏼
I can take over this issue if you like and add you as a coauthor. |
You don't need to add me as a co-author, I'll take on another issue |
I will add you, because you didn't very nice work on this. Moreover, for the tests I'll likely copy what you did verbatim 😎 |
I guess you meant "did" instead of "didn't"😁 But anyway, I appreciate that |
I indeed meant |
If you approve of this solution, then I will add the necessary documentation
Closes #20100
/cc @geoand, @FroMage, @stuartwdouglas