-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
Accept header with trailing comma produces HTTP "406 Not Acceptable" #23241
Comments
What is your use case for that? What client is sending the Accept request header with a trailing comma? |
I'm using an HTTP client named Paw. It sends that request from its built in oauth2 client. Although it seems to be an invalid header, it did work before. |
Thanks for the feedback. I've labeled this as a regression. |
The following test passes against the @Test
public void parseMediaTypesWithTrailingComma() {
List<MediaType> mediaTypes = MediaType.parseMediaTypes("text/plain, text/html, ");
assertNotNull("No media types returned", mediaTypes);
assertEquals("Incorrect number of media types", 2, mediaTypes.size());
} The following fails on @Test
public void parseMimeTypesWithTrailingComma() {
List<MimeType> mimeTypes = MimeTypeUtils.parseMimeTypes("text/plain, text/html,");
assertThat(mimeTypes).as("No mime types returned").isNotNull();
assertThat(mimeTypes.size()).as("Invalid number of mime types").isEqualTo(2);
} |
Spring version: 5.1.8.RELEASE
Send a http request with header like this, containing
,
at the end.Accept: application/json,
HeaderContentNegotiationStrategy
will produce aHttpMediaTypeNotAcceptableException
.That http request works before 5.1.2.RELEASE.
Maybe the cause of this is the parsing method refactoring in this commit f4b05dc.
StringUtils.tokenizeToStringArray(mimeTypes, ",")
will trim tokens and ignore empty tokens by default, but now, the replacement method not support that anymore.The text was updated successfully, but these errors were encountered: