Skip to content
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

AwsProxyHttpServletRequest#getLocale incorrect for locales with country subtag #511

Closed
kerkhofsd opened this issue Apr 14, 2023 · 0 comments
Assignees

Comments

@kerkhofsd
Copy link
Contributor

Serverless Java Container version: 1.9.1

Implementations: Spring Boot 2

Framework version: SpringBoot 2.7.10

Frontend service: REST API

Deployment method: Serverless Framework

Scenario

We are relying on Spring's AcceptHeaderLocaleResolver to store the Locale from the Accept-Language header in the LocaleContextHolder.
This AcceptHeaderLocaleResolver uses HttpServletRequest#getLocale() to retrieve the locale from the request. The HttpServletRequest implementation is provided by the aws-serverless-java-container as AwsProxyHttpServletRequest

Expected behavior

AwsProxyHttpServletRequest#getLocale() provides a correct locale, both for locales with (e.g. en-GB) and without (e.g. en) a country tag.

Actual behavior

AwsProxyHttpServletRequest#getLocale() constructs a Locale from the Accept-Language header using the single value Locale constructor.
For values containing a country tag (e.g. en-GB), an incorrect locale is constructed with en-gb as language code and no country code.

Suggested solution

Use Locale#forLanguageTag to construct the locale from the Accept-Language header value.

Additional info

On first sight I would say that AwsHttpApiV2ProxyHttpServletRequest has the same problem.

@kerkhofsd kerkhofsd changed the title AwsProxyHttpServletRequest#getLocale incorrect for locales with country part AwsProxyHttpServletRequest#getLocale incorrect for locales with country subtag Apr 14, 2023
deki added a commit that referenced this issue Apr 14, 2023
gh-511 Support Accept-Language header values containing country subtag
@deki deki self-assigned this Apr 14, 2023
@deki deki closed this as completed Apr 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants