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

Remove unnecessary content type checks #37646

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public abstract class ResteasyReactiveRequestContext
private OutputStream outputStream;
private OutputStream underlyingOutputStream;
private FormData formData;
private boolean producesChecked;

public ResteasyReactiveRequestContext(Deployment deployment,
ThreadSetupAction requestContext, ServerRestHandler[] handlerChain, ServerRestHandler[] abortHandlerChain) {
Expand Down Expand Up @@ -796,6 +797,14 @@ public void initPathSegments() {
}
}

public void setProducesChecked(boolean checked) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is introducing a ConcurrentHashMap::put there, but TBH it's still better than performing the check twice I think...
2 qq:

  1. ClassRouting vs FixedProduces handler's are always running in that order?
  2. Do we have other mechanism to store this information as a plain field somewhere instead, in the context?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ClassRouting vs FixedProduces handler's are always running in that order?

Yes.

Do we have other mechanism to store this information as a plain field somewhere instead, in the context?

We certainly can, but I was removing fields from the context because it was getting to big and we wanted to make it fit better in cache lines :)

Copy link
Contributor

Choose a reason for hiding this comment

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

I can check with JOL, and if it is within some padding I am +1 to move it to a field, it sadly can matter in bench-marketing :"/ but need to be sure that's free

producesChecked = checked;
}

public boolean isProducesChecked() {
return producesChecked;
}

@Override
public Object getHeader(String name, boolean single) {
if (httpHeaders == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ public void handle(ResteasyReactiveRequestContext requestContext) throws Excepti
throw new NotAcceptableException(INVALID_ACCEPT_HEADER_MESSAGE);
}
}

requestContext.setProducesChecked(true);
}

requestContext.restart(target.value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public FixedProducesHandler(MediaType mediaType, EntityWriter writer) {
@Override
public void handle(ResteasyReactiveRequestContext requestContext) throws Exception {
List<String> acceptValues = (List<String>) requestContext.getHeader(HttpHeaders.ACCEPT, false);
if (acceptValues.isEmpty()) {
if (acceptValues.isEmpty() || requestContext.isProducesChecked()) {
requestContext.setResponseContentType(mediaType);
requestContext.setEntityWriter(writer);
} else {
Expand Down