Add HttpHeaders#setAcceptLanguageAsLocale(Locale)

Issue: SPR-15024
This commit is contained in:
Sebastien Deleuze 2016-12-20 22:29:48 +01:00
parent 82c1c859d9
commit 712a63205c
2 changed files with 12 additions and 0 deletions

View File

@ -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

View File

@ -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