You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Accept header with trailing comma produces HTTP "406 Not Acceptable" #23241
Send a http request with header like this, containing , at the end.
Accept: application/json,
HeaderContentNegotiationStrategy will produce a HttpMediaTypeNotAcceptableException.
org.springframework.web.HttpMediaTypeNotAcceptableException: Could not parse 'Accept' header [application/json,]: Invalid mime type "": 'mimeType' must not be empty
at org.springframework.web.accept.HeaderContentNegotiationStrategy.resolveMediaTypes(HeaderContentNegotiationStrategy.java:59) ~[spring-web-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
at org.springframework.web.accept.ContentNegotiationManager.resolveMediaTypes(ContentNegotiationManager.java:124) ~[spring-web-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.getAcceptableMediaTypes(AbstractMessageConverterMethodProcessor.java:391) ~[spring-webmvc-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:229) ~[spring-webmvc-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.HttpEntityMethodProcessor.handleReturnValue(HttpEntityMethodProcessor.java:225) ~[spring-webmvc-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:82) ~[spring-web-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
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.
changed the title [-]Accept header ends with "," produces HTTP "406 Not Acceptable"[/-][+]Accept header with trailing comma produces HTTP "406 Not Acceptable"[/+]on Jul 6, 2019
Activity
sbrannen commentedon Jul 5, 2019
What is your use case for that?
What client is sending the Accept request header with a trailing comma?
j3r0lin commentedon Jul 5, 2019
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.
[-]Accept header ends with "," produces HTTP "406 Not Acceptable"[/-][+]Accept header with trailing comma produces HTTP "406 Not Acceptable"[/+]sbrannen commentedon Jul 6, 2019
Thanks for the feedback. I've labeled this as a regression.
sbrannen commentedon Jul 6, 2019
The following test passes against the
v5.1.2.RELEASEtag and fails on the current5.1.xbranch (beginning with thev5.1.3.RELEASEtag).The following fails on
master.Ignore empty entries when parsing MediaTypes and MimeTypes