Skip to content

AwsProxyHttpServletRequest#getLocale incorrect for locales with country subtag #511

@kerkhofsd

Description

@kerkhofsd

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions