Skip to content

Commit

Permalink
Fix HttpHeaders.getAcceptableLanguages() on empty headers
Browse files Browse the repository at this point in the history
`jakarta.ws.rs.core.HttpHeaders.getAcceptableLanguages` requires
that a wildcard locale is returned, if no acceptable language is
specified. The previous behavior returned an empty list.

Closes #44253
  • Loading branch information
koplas committed Nov 3, 2024
1 parent 0fbfc31 commit 5ad6ccb
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public class HeaderUtil {
private static final List<Locale> LANGUAGE_WILDCARD = List.of(Locale.ROOT);

private static final ClassValue<RuntimeDelegate.HeaderDelegate<?>> HEADER_DELEGATE_CACHE = new ClassValue<>() {
@Override
Expand Down Expand Up @@ -293,7 +294,7 @@ public static List<MediaType> getAcceptableMediaTypes(MultivaluedMap<String, ? e
public static List<Locale> getAcceptableLanguages(MultivaluedMap<String, ? extends Object> headers) {
List<?> accepts = headers.get(HttpHeaders.ACCEPT_LANGUAGE);
if (accepts == null || accepts.isEmpty())
return Collections.emptyList();
return LANGUAGE_WILDCARD;
List<WeightedLanguage> languages = new ArrayList<WeightedLanguage>();
for (Object obj : accepts) {
if (obj instanceof Locale) {
Expand Down

0 comments on commit 5ad6ccb

Please sign in to comment.