Add set/getContentLanguage() to HttpHeaders

Issue: SPR-14536
This commit is contained in:
Sebastien Deleuze
2016-12-15 17:26:40 +01:00
parent 9764d57433
commit 36da299f96
2 changed files with 37 additions and 0 deletions

View File

@@ -762,6 +762,32 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
return ContentDisposition.empty();
}
/**
* Set the {@link Locale} of the content language,
* as specified by the {@literal Content-Language} header.
* <p>Use {@code set(CONTENT_LANGUAGE, ...)} if you need
* to set multiple content languages.</p>
*/
public void setContentLanguage(Locale locale) {
Assert.notNull(locale, "'locale' must not be null");
set(CONTENT_LANGUAGE, locale.toLanguageTag());
}
/**
* Return the first {@link Locale} of the content languages,
* as specified by the {@literal Content-Language} header.
* <p>Returns {@code null} when the content language is unknown.
* <p>Use {@code getValuesAsList(CONTENT_LANGUAGE)} if you need
* to get multiple content languages.</p>
*/
public Locale getContentLanguage() {
return getValuesAsList(CONTENT_LANGUAGE)
.stream()
.findFirst()
.map(Locale::forLanguageTag)
.orElse(null);
}
/**
* Set the length of the body in bytes, as specified by the
* {@code Content-Length} header.