Repository navigation
Tomcat's new 'maxLocaleCount' property cannot be easily configured - #52367
Conversation
|
It looks like Tomcat has been updated to ignore locales beyond the maxLocaleCount limit. This seems to make this PR somewhat less necessary, but I'll keep it open for now. |
Our default position is to align with Tomcat.
I tempted to still offer a property in case users need the old behavior. It's probably possible to use a customizer, but the property is nicer IMO. |
|
Thanks, @philwebb. I've kept the default aligned with Tomcat ( |
Tomcat 11.0.27 has introduced a new connector attribute, maxLocaleCount, that limits the number of locales parsed from a request's Accept-Language header. To ease its configuration, this commit introduces a server.tomcat.max-locale-count property. The default is aligned with that of Tomcat (10). Signed-off-by: be-hase <hsb.1014@gmail.com> See spring-projectsgh-52367
e34cf1c to
f05b9dc
Compare
|
Thanks, @be-hase. |
|
thanks :) |
This PR adds a
server.tomcat.max-locale-countproperty to configure Tomcat's newmaxLocaleCountconnector attribute.Background
Tomcat 11.0.27 introduced this attribute with a default of
10(apache/tomcat@c45c9b4), and Spring Boot
4.0.9 and 4.1.2 ship with that version. When a request's
Accept-Languageheader containsmore locales than the limit,
HttpServletRequest.getLocale()/getLocales()throw anIllegalArgumentException. This affects anything that resolves the request's locale, suchas Spring MVC's
AcceptHeaderLocaleResolver.We ran into this in production after upgrading: requests from browsers with many languages
configured started failing. The change is easy to miss, as Tomcat's changelog only describes
it as "Optimize Accept-Language header processing and use of resource bundles for
localization".
Other applications will likely need to change this limit as we did. It would be good if
they could do so with a property, rather than having to write a
WebServerFactoryCustomizer.Changes
server.tomcat.max-locale-count, following the approach taken forserver.tomcat.max-part-countandserver.tomcat.max-part-header-size(Upgrade to Tomcat 10.1.42 #45869).10), and a value of less than0means no limit.NoSuchMethodErroris ignored for Tomcat < 11.0.27.Default value
I'd like your opinion on this. A request to change Tomcat's default back to
-1wasdeclined (apache/tomcat#1096), so the question is whether Spring Boot should keep Tomcat's
default or use its own:
10(align with Tomcat): consistent withmax-part-countandmax-part-header-size,and with the existing tests that check that property defaults match the connector defaults.
-1(no limit): keeps the behavior from before Tomcat 11.0.27, so that a Spring Bootpatch upgrade doesn't break applications that receive such requests.
I'm happy to update the PR to use
-1if you prefer.