-
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
Make sure the default content type is available in ContainerResponseFilters and WriterInterceptors when returning Response #44166
base: main
Are you sure you want to change the base?
Conversation
This will need a test but I would like for @geoand to make sure I'm not hallucinating :). |
Thanks! Seems reasonable to me. |
43ab439
to
8584ea8
Compare
@geoand I tried to fix the other issue with I also added tests for the first fix. That being said, I just ran the TCK locally and... the second commit introduces a test failure in @Test
public void defaultResponseErrorTest() throws Fault {
setProperty(Property.REQUEST, buildRequest(Request.POST, "error"));
setProperty(Property.CONTENT, "anything");
setProperty(Property.REQUEST_HEADERS, "Accept: text/*");
setProperty(Property.STATUS_CODE, getStatusCode(Status.NOT_ACCEPTABLE));
invoke();
} The resource is this one: @POST
@Produces("text/*")
public Response response(String msg) {
return Response.ok(msg).build();
} So it basically expects an error when the It seems a bit odd to me and in contradiction with what I understand from https://jakarta.ee/specifications/restful-ws/4.0/jakarta-restful-ws-spec-4.0#determine_response_type . The only thing that makes sense here would be if /cc @FroMage |
The one from the response can be null if we return a partial response but the type is defined by @produces. We need to consider the one from the context. Fixes quarkusio#34839
8584ea8
to
6497776
Compare
Yeah, what you describe does seem reasonable, but I am stopped trying to make sense of the TCK when it comes to media types... |
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.
LGTM.
@gsmet: the failure is legit according to the algo described in the spec. You have You haven't been able to find a proper content type, because neither Now, we could deduct it from the value being passed to the |
@FroMage interesting. I'll dig a bit more then. |
6497776
to
be55617
Compare
@FroMage thanks for putting me in the right direction, it was actually an ugly bug in my newly written code. From what I can see the TCK is passing correctly now. |
Even when we use Response, it's interesting to push the default content type to the context as it might get used by ContainerResponseFilters. If the Response actually overrides it, it's all taken care of. Fixes quarkusio#34839
be55617
to
27381e3
Compare
Status for workflow
|
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.
Not sure about this change, there's a bit of code I don't understand yet 😅
} | ||
} | ||
if (res == null) { // fallback to ensure that MessageBodyWriter is passed the proper media type | ||
res = mediaTypeList.negotiateProduces(requestContext.serverRequest().getRequestHeader(HttpHeaders.ACCEPT)) |
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.
Oh, I see, I suppose that requestContext.getHttpHeaders()
might have been overridden by a filter, while requestContext.serverRequest()
is immutable?
Otherwise I don't understand why these would be different. Besides the fact that I suspect that here, getRequestHeader
will not properly split the header…
I'm a bit lost here :-/
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 haven't invented this code, it comes straight from VariableProducesHandler
. I just copied the exact same behavior as I supposed that's what we wanted.
And I agree I don't really understand what is going on here either.
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.
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.
Yeah, lovely stuff... Anything media type related is horrible - both in the spec and the impl
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 any case, I think being consistent in how we handle things for Response
/not Response
is a good thing.
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.
Definitely agreed
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.
Maybe I should add a comment in both classes though so that they are kept in sync if updates are made.
I will do that once we agree with the big picture.
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.
A comment would be nice because if we don't understand why it's like this now, we will also not understand it later if an issue is raised and we need to know that there are two places where the same behaviour occurs. Or you refactor the two into a single method, also with a comment saying this is fishy and point at this PR for this discussion, for later archeology.
Fixes #34839