提交 712a6320 编写于 作者: S Sebastien Deleuze

Add HttpHeaders#setAcceptLanguageAsLocale(Locale)

Issue: SPR-15024
上级 82c1c859
......@@ -475,6 +475,15 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
return Collections.emptyList();
}
/**
* A variant of {@link #setAcceptLanguage(List)} that sets the {@literal Accept-Language}
* header value to the specified locale.
* @since 5.0
*/
public void setAcceptLanguageAsLocale(Locale locale) {
setAcceptLanguage(Collections.singletonList(new Locale.LanguageRange(locale.toLanguageTag())));
}
/**
* A variant of {@link #getAcceptLanguage()} that converts each
* {@link java.util.Locale.LanguageRange} to a {@link Locale} and returns
......
......@@ -438,6 +438,9 @@ public class HttpHeadersTests {
assertEquals(expectedRanges, headers.getAcceptLanguage());
assertEquals(Locale.forLanguageTag("fr-ch"), headers.getAcceptLanguageAsLocale());
headers.setAcceptLanguageAsLocale(Locale.FRANCE);
assertEquals(Locale.FRANCE, headers.getAcceptLanguageAsLocale());
}
@Test
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册