-
Notifications
You must be signed in to change notification settings - Fork 38.4k
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
Spring Web should process requests with empty/invalid mime type [SPR-14309] #18881
Comments
Juergen Hoeller commented Catching |
IMHO, according to RFC7231 section 3.1.1.5, if the content-type is missing, it should assume a media type of The problem is, as the content type is not mandatory, But... we are in Spring, and Spring is awesome at giving us options. That problem was blocking, for my company, because when accessing to our OpenText ECM API, sometimes the content-type is missing on 4xx or 5xx responses... @Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
ClientHttpResponse response = execution.execute(request, body);
try {
response.getHeaders().getContentType();
} catch (InvalidMediaTypeException exception) {
response.getHeaders().put(HttpHeaders.CONTENT_TYPE, Collections.singletonList(MediaType.APPLICATION_JSON_UTF8_VALUE));
}
return response;
} Be careful to use a Have fun... waiting for the fix... |
Where exactly is it failing, in |
BTW you're commenting on issue that is related but in a very different part of the codebase. Can you please create a separate issue for it? |
Yes, it is the in |
Asking for further changes on an issue resolved almost 3 years ago isn't going to get this any further. Also keep in mind a change like that at the level of |
Nazar Vishka opened SPR-14309 and commented
If a client is sending a POST message with an empty/invalid header 'Content-Type' the request fails with InvalidMediaTypeException.
I think that org.springframework.http.HttpHeaders#getContentType should handle InvalidMediaTypeException exception and return null in such cases or you should change behaviour of org.springframework.http.MediaType#parseMediaType
Affects: 4.2.6
Issue Links:
Backported to: 4.2.7
The text was updated successfully, but these errors were encountered: