File tree 2 files changed +37
-0
lines changed
main/java/org/springframework/http
test/java/org/springframework/http
2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -762,6 +762,32 @@ public ContentDisposition getContentDisposition() {
762
762
return ContentDisposition .empty ();
763
763
}
764
764
765
+ /**
766
+ * Set the {@link Locale} of the content language,
767
+ * as specified by the {@literal Content-Language} header.
768
+ * <p>Use {@code set(CONTENT_LANGUAGE, ...)} if you need
769
+ * to set multiple content languages.</p>
770
+ */
771
+ public void setContentLanguage (Locale locale ) {
772
+ Assert .notNull (locale , "'locale' must not be null" );
773
+ set (CONTENT_LANGUAGE , locale .toLanguageTag ());
774
+ }
775
+
776
+ /**
777
+ * Return the first {@link Locale} of the content languages,
778
+ * as specified by the {@literal Content-Language} header.
779
+ * <p>Returns {@code null} when the content language is unknown.
780
+ * <p>Use {@code getValuesAsList(CONTENT_LANGUAGE)} if you need
781
+ * to get multiple content languages.</p>
782
+ */
783
+ public Locale getContentLanguage () {
784
+ return getValuesAsList (CONTENT_LANGUAGE )
785
+ .stream ()
786
+ .findFirst ()
787
+ .map (Locale ::forLanguageTag )
788
+ .orElse (null );
789
+ }
790
+
765
791
/**
766
792
* Set the length of the body in bytes, as specified by the
767
793
* {@code Content-Length} header.
Original file line number Diff line number Diff line change @@ -439,4 +439,15 @@ public void acceptLanguage() {
439
439
assertArrayEquals (languageArray , languages .toArray ());
440
440
}
441
441
442
+ @ Test
443
+ public void contentLanguage () {
444
+ assertNull (headers .getContentLanguage ());
445
+ headers .setContentLanguage (Locale .FRANCE );
446
+ assertEquals (Locale .FRANCE , headers .getContentLanguage ());
447
+ assertEquals ("fr-FR" , headers .getFirst (HttpHeaders .CONTENT_LANGUAGE ));
448
+ headers .clear ();
449
+ headers .set (HttpHeaders .CONTENT_LANGUAGE , Locale .GERMAN .toLanguageTag () + ", " + Locale .CANADA );
450
+ assertEquals (Locale .GERMAN , headers .getContentLanguage ());
451
+ }
452
+
442
453
}
You can’t perform that action at this time.
0 commit comments