Repository navigation
Conversation
The locales that were retained depended on the order of the entries in the Accept-Language header(s) rather than on their quality values, as parsing stopped after maxLocaleCount + 1 entries. The order of the entries cannot be relied upon (RFC 9110, section 12.5.4) so the whole header is now parsed and the entries with the highest quality values are retained. The Locale is created lazily so it is still only created for the retained entries. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
Thank you for your contribution, but I do not see a use case for this. Please use the maxLocaleCount header instead if you need to. Please do not reopen the issue. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to c639c7e ("Allow maxLocaleCount to soft fail") and the discussion in https://lists.apache.org/thread/6wtt1tks7y3c1lz76rpb0pcgn0om3dnc
Problem
Now that extra locales are ignored rather than the request being rejected, which locales are kept matters. Currently,
parseLocalesHeader()stops parsing aftermaxLocaleCount + 1entries and the sorting by quality only happens afterwards, so the locales that are kept depend on the order of the entries in the header rather than on their quality values.For example, with
maxLocaleCount=2:results in
[it, fr], sogetLocale()returnsitand the most preferred language (ja) is silently dropped.RFC 9110, section 12.5.4 says that the order of the entries cannot be relied upon:
Listing entries in descending quality order is common practice among user agents, but it is not required, so a well-behaved client can be affected.
Change
The aim of the limit (not creating
Localeobjects for entries that can never be used) is kept:AcceptLanguagecreates itsLocalelazily, on the first call togetLocale(). The parsers only record the language tag and the quality value.parseLocalesHeader()parses the whole header and retains themaxLocaleCount + 1entries with the highest quality values across allAccept-Languageheaders. Entries with the same quality value keep header order, as before. The+ 1is kept so thatparseLocales()can still detect that the limit was exceeded and log the existing message.Localeis only created for the retained entries, so at mostmaxLocaleCount + 1Localeobjects are created per header. Tokenizing the rest of the header is cheap and is already bounded by the maximum header size.parseLocalesHeader()method is unchanged.maxLocaleCount(HTTP and AJP connectors) now describes which locales are retained.Tests
TestRequest:Accept-LanguageheadersTestAcceptLanguage: theLocaleis created lazily, and only once