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

Add support for setting response status and response headers support via annotations #20242

Closed
wants to merge 4 commits into from

Conversation

steel-judoka
Copy link
Contributor

@steel-judoka steel-judoka commented Sep 17, 2021

If you approve of this solution, then I will add the necessary documentation

Closes #20100

/cc @geoand, @FroMage, @stuartwdouglas

@quarkus-bot

This comment has been minimized.

@steel-judoka steel-judoka changed the title Response status and Response headers support added #20100 Response status and Response headers support added Sep 17, 2021
Copy link
Contributor

@geoand geoand left a 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 geoand changed the title Response status and Response headers support added Add support for setting response status and response headers support via annotations Sep 17, 2021
@steel-judoka
Copy link
Contributor Author

@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

@geoand
Copy link
Contributor

geoand commented Sep 17, 2021

Thanks for the update!

I would argue that the annotations should not work of the return type is Response or RestResponse, but we need more feedback on this

@@ -132,6 +133,9 @@
*/
private List<UriMatch> matchedURIs;

private Map<String, String> responseHeaders;
private Integer responseStatus;
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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.

@steel-judoka
Copy link
Contributor Author

@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

@geoand
Copy link
Contributor

geoand commented Sep 20, 2021

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();
Copy link
Contributor

@geoand geoand Sep 21, 2021

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

Copy link
Contributor Author

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

Copy link
Contributor

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 :)

Copy link
Contributor Author

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏼

@quarkus-bot quarkus-bot bot added the triage/invalid This doesn't seem right label Sep 21, 2021
@geoand
Copy link
Contributor

geoand commented Sep 21, 2021

I can take over this issue if you like and add you as a coauthor.

@steel-judoka
Copy link
Contributor Author

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

@geoand
Copy link
Contributor

geoand commented Sep 21, 2021

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 😎

@steel-judoka
Copy link
Contributor Author

steel-judoka commented Sep 21, 2021

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

@geoand
Copy link
Contributor

geoand commented Sep 21, 2021

I indeed meant did :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/rest triage/invalid This doesn't seem right
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add the ability to set HTTP headers and Response status when returning Reactive Types from RESTEasy Reactive
2 participants