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

500 response for ResourceHttpRequestHandler when requested range is not satisfied #34490

Open
NielsCW opened this issue Feb 25, 2025 · 3 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged or decided on

Comments

@NielsCW
Copy link

NielsCW commented Feb 25, 2025

When sending a request to a resource with an invalid range, the server responds with a 500 Internal server error instead of 416 Requested range not satisfiable.

When the ResourceHttpRequestHandler is executed with an invalid range then it will call the HttpServletResponse.sendError(HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE) method:

catch (IllegalArgumentException ex) {
response.setHeader(HttpHeaders.CONTENT_RANGE, "bytes */" + resource.contentLength());
response.sendError(HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
}
Further down the processing line this will not result in a ProblemDetail body response, so the writeWithMessageConverters method in AbstractMessageConverterMethodProcessor will throw a HttpMessageNotWritableException from:
if (isContentTypePreset || !CollectionUtils.isEmpty(producibleMediaTypes)) {
throw new HttpMessageNotWritableException(
"No converter for [" + valueType + "] with preset Content-Type '" + contentType + "'");
}
(Where valueType is java.util.LinkedHashMap and contentType is multipart/form-data)

@NielsCW NielsCW changed the title 500 error when requested range is not satisfied 500 response for ResourceHttpRequestHandler when requested range is not satisfied Feb 25, 2025
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 25, 2025
@bclozel bclozel added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Feb 25, 2025
@NielsCW
Copy link
Author

NielsCW commented Feb 26, 2025

An example that uses spring-content containing a WebTestClient test that reproduces the issue demo-api.zip

@rstoyanchev rstoyanchev self-assigned this Feb 27, 2025
@rstoyanchev
Copy link
Contributor

rstoyanchev commented Feb 27, 2025

The demo project is missing the (Gradle) build file. Could you provide that as well?

@rstoyanchev rstoyanchev added the status: waiting-for-feedback We need additional information before we can continue label Feb 27, 2025
@NielsCW
Copy link
Author

NielsCW commented Feb 27, 2025

Sure, here is the updated demo-api.zip

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Feb 27, 2025
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) status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged or decided on
Projects
None yet
Development

No branches or pull requests

4 participants