70.10 Use Tomcat’s LegacyCookieProcessor
The embedded Tomcat used by Spring Boot does not support "Version 0" of the Cookie format out of the box, and you may see the following error:
java.lang.IllegalArgumentException: An invalid character [32] was present in the Cookie value
If at all possible, you should consider updating your code to only store values compliant with later Cookie specifications. If, however, you’re unable to change the way that cookies are written, you can instead configure Tomcat to use a LegacyCookieProcessor
. To switch to the LegacyCookieProcessor
use an EmbeddedServletContainerCustomizer
bean that adds a TomcatContextCustomizer
:
_@Bean_ public EmbeddedServletContainerCustomizer cookieProcessorCustomizer() { return new EmbeddedServletContainerCustomizer() { _@Override_ public void customize(ConfigurableEmbeddedServletContainer container) { if (container instanceof TomcatEmbeddedServletContainerFactory) { ((TomcatEmbeddedServletContainerFactory) container) .addContextCustomizers(new TomcatContextCustomizer() { _@Override_ public void customize(Context context) { context.setCookieProcessor(new LegacyCookieProcessor()); } }); } } }; }