Skip to content

handleEmptyBody of RequestBodyAdvice should apply also when content-type is not set #30522

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

Closed
joca-bt opened this issue May 23, 2023 · 0 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@joca-bt
Copy link

joca-bt commented May 23, 2023

The code that determines whether to run handleEmptyBody depends on other factors besides the body not being provided. I have attached a simple application that shows the issue (test.zip). The application is comprised of 1 controller and 1 advice.

If the endpoint is called without a body and no content type, the advice will not run (note that the endpoint returns 200):

curl -X POST http://localhost:8080/identity

If the endpoint is called without a body but with a content type, the advice will run (note that the endpoint returns 200):

curl -X POST http://localhost:8080/identity -H 'Content-Type: application/json'

If we inspect AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters() we see that in the first case the content type is set to application/octet-stream while in the second it is set to application/json. The converter is not able to handle application/octet-stream so the if and handleEmptyBody will not run. Sending the content type header is unnecessary when there is no body, so the behaviour of running handleEmptyBody shouldn't depend on it.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label May 23, 2023
@rstoyanchev rstoyanchev self-assigned this Nov 8, 2023
@rstoyanchev rstoyanchev added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 8, 2023
@rstoyanchev rstoyanchev added this to the 6.1.0 milestone Nov 8, 2023
@rstoyanchev rstoyanchev changed the title handleEmptyBody of RequestBodyAdvice does not always run when there is no body handleEmptyBody of RequestBodyAdvice should apply also when content-type is not set Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants