Apply getAcceptLanguageAsLocale and encodeUrl
Apply the new HttpHeaders#getAcceptLanguageAsLocale() in places where it was hardcoded or defaulting. Apply ServerHttpResponse.encodeUrl in RequestContext. Issue: SPR-15024
This commit is contained in:
@@ -317,7 +317,8 @@ class DefaultServerResponseBuilder implements ServerResponse.BodyBuilder {
|
||||
ServerHttpResponse response = exchange.getResponse();
|
||||
writeStatusAndHeaders(response);
|
||||
MediaType contentType = exchange.getResponse().getHeaders().getContentType();
|
||||
Locale locale = Locale.ENGLISH; // TODO: resolve locale
|
||||
Locale acceptLocale = exchange.getRequest().getHeaders().getAcceptLanguageAsLocale();
|
||||
Locale locale = (acceptLocale != null ? acceptLocale : Locale.getDefault());
|
||||
Stream<ViewResolver> viewResolverStream = strategies.viewResolvers().get();
|
||||
return Flux.fromStream(viewResolverStream)
|
||||
.concatMap(viewResolver -> viewResolver.resolveViewName(this.name, locale))
|
||||
|
||||
@@ -76,7 +76,9 @@ public class RequestContext {
|
||||
this.model = model;
|
||||
this.messageSource = messageSource;
|
||||
this.defaultHtmlEscape = null; // TODO
|
||||
this.locale = Locale.getDefault(); // TODO
|
||||
|
||||
Locale acceptLocale = exchange.getRequest().getHeaders().getAcceptLanguageAsLocale();
|
||||
this.locale = acceptLocale != null ? acceptLocale : Locale.getDefault();
|
||||
this.timeZone = TimeZone.getDefault(); // TODO
|
||||
}
|
||||
|
||||
@@ -102,7 +104,6 @@ public class RequestContext {
|
||||
|
||||
/**
|
||||
* Return the current Locale.
|
||||
* TODO: currently this is Locale.getDefault()
|
||||
*/
|
||||
public final Locale getLocale() {
|
||||
return this.locale;
|
||||
@@ -118,7 +119,6 @@ public class RequestContext {
|
||||
|
||||
/**
|
||||
* Change the current locale to the specified one.
|
||||
* TODO: currently simply change the internal field
|
||||
*/
|
||||
public void changeLocale(Locale locale) {
|
||||
this.locale = locale;
|
||||
@@ -126,7 +126,6 @@ public class RequestContext {
|
||||
|
||||
/**
|
||||
* Change the current locale to the specified locale and time zone context.
|
||||
* TODO: currently simply change the internal fields
|
||||
*/
|
||||
public void changeLocale(Locale locale, TimeZone timeZone) {
|
||||
this.locale = locale;
|
||||
@@ -176,8 +175,7 @@ public class RequestContext {
|
||||
*/
|
||||
public String getContextUrl(String relativeUrl) {
|
||||
String url = getContextPath() + relativeUrl;
|
||||
// TODO: this.response.encodeURL(url)
|
||||
return url;
|
||||
return getExchange().getResponse().encodeUrl(url);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -194,8 +192,7 @@ public class RequestContext {
|
||||
String url = getContextPath() + relativeUrl;
|
||||
UriTemplate template = new UriTemplate(url);
|
||||
url = template.expand(params).toASCIIString();
|
||||
// TODO: this.response.encodeURL(url)
|
||||
return url;
|
||||
return getExchange().getResponse().encodeUrl(url);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -212,7 +212,9 @@ public class ViewResolutionResultHandler extends AbstractHandlerResultHandler
|
||||
|
||||
Mono<List<View>> viewsMono;
|
||||
Model model = result.getModel();
|
||||
Locale locale = Locale.getDefault(); // TODO
|
||||
|
||||
Locale acceptLocale = exchange.getRequest().getHeaders().getAcceptLanguageAsLocale();
|
||||
Locale locale = acceptLocale != null ? acceptLocale : Locale.getDefault();
|
||||
|
||||
Class<?> clazz = elementType.getRawClass();
|
||||
if (clazz == null) {
|
||||
|
||||
@@ -170,7 +170,10 @@ public class FreeMarkerView extends AbstractUrlBasedView {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Rendering FreeMarker template [" + getUrl() + "].");
|
||||
}
|
||||
Locale locale = Locale.getDefault(); // TODO
|
||||
|
||||
Locale acceptLocale = exchange.getRequest().getHeaders().getAcceptLanguageAsLocale();
|
||||
Locale locale = acceptLocale != null ? acceptLocale : Locale.getDefault();
|
||||
|
||||
DataBuffer dataBuffer = exchange.getResponse().bufferFactory().allocateBuffer();
|
||||
try {
|
||||
Charset charset = getCharset(contentType).orElse(getDefaultCharset());
|
||||
|
||||
Reference in New Issue
Block a user