Add HttpHeaders#setAcceptLanguageAsLocale(Locale)
Issue: SPR-15024
This commit is contained in:
parent
82c1c859d9
commit
712a63205c
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue