Skip to content

Commit 4ec2844

Browse files
committed
Honor overridden AcceptHeaderLocaleContextResolver.getDefaultLocale()
Closes gh-24871
1 parent d9eacaa commit 4ec2844

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

spring-web/src/main/java/org/springframework/web/server/i18n/AcceptHeaderLocaleContextResolver.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -39,6 +39,7 @@
3939
* @author Sebastien Deleuze
4040
* @author Juergen Hoeller
4141
* @since 5.0
42+
* @see HttpHeaders#getAcceptLanguageAsLocales()
4243
*/
4344
public class AcceptHeaderLocaleContextResolver implements LocaleContextResolver {
4445

@@ -76,6 +77,7 @@ public void setDefaultLocale(@Nullable Locale defaultLocale) {
7677

7778
/**
7879
* The configured default locale, if any.
80+
* <p>This method may be overridden in subclasses.
7981
*/
8082
@Nullable
8183
public Locale getDefaultLocale() {
@@ -98,7 +100,7 @@ public LocaleContext resolveLocaleContext(ServerWebExchange exchange) {
98100
@Nullable
99101
private Locale resolveSupportedLocale(@Nullable List<Locale> requestLocales) {
100102
if (CollectionUtils.isEmpty(requestLocales)) {
101-
return this.defaultLocale; // may be null
103+
return getDefaultLocale(); // may be null
102104
}
103105
List<Locale> supportedLocales = getSupportedLocales();
104106
if (supportedLocales.isEmpty()) {
@@ -128,7 +130,8 @@ else if (languageMatch == null) {
128130
return languageMatch;
129131
}
130132

131-
return (this.defaultLocale != null ? this.defaultLocale : requestLocales.get(0));
133+
Locale defaultLocale = getDefaultLocale();
134+
return (defaultLocale != null ? defaultLocale : requestLocales.get(0));
132135
}
133136

134137
@Override

spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/AcceptHeaderLocaleResolver.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -83,6 +83,7 @@ public void setDefaultLocale(@Nullable Locale defaultLocale) {
8383

8484
/**
8585
* The configured default locale, if any.
86+
* <p>This method may be overridden in subclasses.
8687
* @since 4.3
8788
*/
8889
@Nullable

0 commit comments

Comments
 (0)