Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Improved Problem Response Content-Type headers #80

Merged
merged 1 commit into from
Dec 17, 2024
Merged

Conversation

rvesse
Copy link
Contributor

@rvesse rvesse commented Dec 16, 2024

Iterates on a change made in the 0.25.0 release where we stopped setting the Content-Type header at all to allow the JAX-RS server to do content negotiation properly. However, turns out that in some corner cases this results in a Problem response being defaulted to
application/octet-stream responses which is rarely useful/helpful.

Therefore this improves the behaviour to make a best effort to add a recognised Content-Type header, when it is compatible with the acceptable content types indicated by the clients Accept header. A new toResponse(HttpHeaders) overload is added to facilitate this, and existing callers of toResponse() updated to call the new method instead.

Also greatly expands the test coverage in this area to validate various scenarios around different combinations of Accept header, resource @Produces headers and the resulting Content-Type header.

Related Issues and PRs

  • Discovered while reviewing Dependabot PRs for the 0.25.0 upgrade e.g. https://github.com/Telicent-io/user-preferences-service/actions/runs/12345464738/job/34449662984 was failing with the following:

    TestUserPreferencesServerBlocking>AbstractUserPreferencesServerTests.givenAuthenticatedUser_whenSavingQueryWithInvalidId_thenBadRequest:503->AbstractUserPreferencesServerTests.verifyInvalidId:480->AbstractUserPreferencesServerTests.verify:172 » MessageBodyProviderNotFound MessageBodyReader not found for media type=application/octet-stream, type=class io.telicent.smart.cache.server.jaxrs.model.Problem, genericType=class io.telicent.smart.cache.server.jaxrs.model.Problem.

    • Using a SNAPSHOT build from this branch those errors no longer occur

@rvesse rvesse added bug Something isn't working enhancement New feature or request labels Dec 16, 2024
@rvesse rvesse self-assigned this Dec 16, 2024
Iterates on a change made in the 0.25.0 release where we stopped setting
the Content-Type header at all to allow the JAX-RS server to do content
negotation properly.  However, turns out that in some corner cases this
results in a Problem response being defaulted to
application/octet-stream responses which is rarely useful/helpful.

Therefore this improves the behaviour to make a best effort to add a
recognised Content-Type header, when it is compatible with the
acceptable content types indicated by the clients Accept header. A new
toResponse(HttpHeaders) overload is added to facilitate this, and
existing callers of toResponse() updated to call the new method instead.

Also greatly expands the test coverage in this area to validate various
scenarios around different combinations of Accept header, resource
@produces headers and the resulting Content-Type header.
@rvesse rvesse merged commit 25100b7 into main Dec 17, 2024
27 checks passed
@rvesse rvesse deleted the problem-content-type branch December 17, 2024 09:18
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants