Bug 59295

Summary: Content-Language headers created by Response.setLocale do not fully represent the locale
Product: Tomcat 8 Reporter: zikfat
Component: CatalinaAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 8.0.28   
Target Milestone: ----   
Hardware: PC   
OS: All   
Attachments: Patch file with a fix. Based off of the trunk of the Tomcat 8.0 branch.

Description zikfat 2016-04-08 22:39:41 UTC
Created attachment 33743 [details]
Patch file with a fix. Based off of the trunk of the Tomcat 8.0 branch.

The org.apache.coyote.Response class's setLocale method sets the Content-Language header based on the Java Locale object passed in, but the language tag it produces is only based on the Locale's language and region. It should allow the full variety of language tags described in RFC 5646.

For example, this code sets a Locale object on a response for the Chinese language, in China, with the traditional chinese script variant:

Locale locale = Locale.forLanguageTag("zh-hant-CN");
response.setLocale(locale);

But the Content-Language header produced in the response will look like this, with the script variant being lost:

Content-Language:zh-CN

I believe the solution is simply to set the Content-Language header by using the Locale's toLanguageTag method instead of manually creating the language tag strings as the setLocale method currently does.
Comment 1 Mark Thomas 2016-04-11 21:07:15 UTC
Thanks for the report and the patch. It has been applied to:
- 9.0.x for 9.0.0.M5
- 8.5.x for 8.5.1
- 8.0.x for 8.0.34