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

If no Accept header is set default to the first 'produces' type #11014

Merged
merged 1 commit into from
Jul 29, 2020

Conversation

stuartwdouglas
Copy link
Member

Currently if the request does not include an Accept header the
method will still be invoked but the content type will not
always be automatically set.

Fixes #10960

@stuartwdouglas stuartwdouglas requested a review from mkouba July 28, 2020 02:50
@geoand geoand added this to the 1.7.0 - master milestone Jul 28, 2020
@@ -539,12 +542,14 @@ void implementInvoke(HandlerDescriptor descriptor, BeanInfo bean, MethodInfo met
MethodDescriptor methodDescriptor = MethodDescriptor
.ofMethod(bean.getImplClazz().name().toString(), method.name(), returnType, parameterTypes);

// If no content-type header is set then try to use the most acceptable content type
// the business method can override this manually if required
invoke.invokeStaticMethod(Methods.ROUTE_HANDLERS_SET_CONTENT_TYPE, routingContext,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that we should only set the content-type header if the business method did not set it manually, i.e. after it was executed. If we set it before then multiple content-type headers may be set to the response.

@@ -87,6 +118,13 @@ Person getPersonUtf8(RoutingContext context) {
return new Person("neo", 12345);
}

@Route(path = "manual-content-type", produces = "application/json")
Copy link
Contributor

Choose a reason for hiding this comment

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

manual-content-type is not a good path for this route. Maybe default-content-type?

String acceptableContentType = context.getAcceptableContentType();
if (acceptableContentType != null) {
response.putHeader(CONTENT_TYPE, acceptableContentType);
response.headersEndHandler(new Handler<Void>() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we use io.vertx.ext.web.RoutingContext.addHeadersEndHandler(Handler<Void>) instead?

Also from perf POV this means one more Handler instance per each request. It's probably negligible but I wonder if the previous approach "set the content type after the route method is executed" represents some serious issue?

Copy link
Member Author

Choose a reason for hiding this comment

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

The previous approach would fail if the method used the RoutingContext to send data, as the headers would have already been written.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, you're right! What about the RoutingContext.addHeadersEndHandler()?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops, forgot to push it.

Currently if the request does not include an Accept header the
method will still be invoked but the content type will not
always be automatically set.

Fixes quarkusio#10960
@mkouba mkouba merged commit 2041ad6 into quarkusio:master Jul 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Produced MIME type declaration not honoured in reactive routes
3 participants