Bug 59295 - Content-Language headers created by Response.setLocale do not fully represent the locale
Summary: Content-Language headers created by Response.setLocale do not fully represent...
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 8
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 8.0.28
Hardware: PC All
: P2 normal (vote)
Target Milestone: ----
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-04-08 22:39 UTC by zikfat
Modified: 2016-04-11 21:07 UTC (History)
0 users



Attachments
Patch file with a fix. Based off of the trunk of the Tomcat 8.0 branch. (874 bytes, patch)
2016-04-08 22:39 UTC, zikfat
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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