Merge branch '5.2.x' into master
This commit is contained in:
commit
bd277819fd
|
|
@ -72,6 +72,8 @@ public final class StringDecoder extends AbstractDataBufferDecoder<String> {
|
||||||
|
|
||||||
private final boolean stripDelimiter;
|
private final boolean stripDelimiter;
|
||||||
|
|
||||||
|
private Charset defaultCharset = DEFAULT_CHARSET;
|
||||||
|
|
||||||
private final ConcurrentMap<Charset, byte[][]> delimitersCache = new ConcurrentHashMap<>();
|
private final ConcurrentMap<Charset, byte[][]> delimitersCache = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -83,6 +85,24 @@ public final class StringDecoder extends AbstractDataBufferDecoder<String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the default character set to fall back on if the MimeType does not specify any.
|
||||||
|
* <p>By default this is {@code UTF-8}.
|
||||||
|
* @param defaultCharset the charset to fall back on
|
||||||
|
* @since 5.2.9
|
||||||
|
*/
|
||||||
|
public void setDefaultCharset(Charset defaultCharset) {
|
||||||
|
this.defaultCharset = defaultCharset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the configured {@link #setDefaultCharset(Charset) defaultCharset}.
|
||||||
|
* @since 5.2.9
|
||||||
|
*/
|
||||||
|
public Charset getDefaultCharset() {
|
||||||
|
return this.defaultCharset;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canDecode(ResolvableType elementType, @Nullable MimeType mimeType) {
|
public boolean canDecode(ResolvableType elementType, @Nullable MimeType mimeType) {
|
||||||
return (elementType.resolve() == String.class && super.canDecode(elementType, mimeType));
|
return (elementType.resolve() == String.class && super.canDecode(elementType, mimeType));
|
||||||
|
|
@ -136,12 +156,12 @@ public final class StringDecoder extends AbstractDataBufferDecoder<String> {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Charset getCharset(@Nullable MimeType mimeType) {
|
private Charset getCharset(@Nullable MimeType mimeType) {
|
||||||
if (mimeType != null && mimeType.getCharset() != null) {
|
if (mimeType != null && mimeType.getCharset() != null) {
|
||||||
return mimeType.getCharset();
|
return mimeType.getCharset();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return DEFAULT_CHARSET;
|
return getDefaultCharset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -411,7 +411,7 @@ public abstract class AbstractMessageConverterMethodProcessor extends AbstractMe
|
||||||
|
|
||||||
try {
|
try {
|
||||||
int status = response.getServletResponse().getStatus();
|
int status = response.getServletResponse().getStatus();
|
||||||
if (status < 200 || status > 299) {
|
if (status < 200 || (status > 299 && status < 400)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -400,6 +400,25 @@ public class RequestResponseBodyMethodProcessorTests {
|
||||||
this.servletRequest.removeAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE);
|
this.servletRequest.removeAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void addContentDispositionHeaderToErrorResponse() throws Exception {
|
||||||
|
ContentNegotiationManagerFactoryBean factory = new ContentNegotiationManagerFactoryBean();
|
||||||
|
factory.addMediaType("pdf", new MediaType("application", "pdf"));
|
||||||
|
factory.afterPropertiesSet();
|
||||||
|
|
||||||
|
RequestResponseBodyMethodProcessor processor = new RequestResponseBodyMethodProcessor(
|
||||||
|
Collections.singletonList(new StringHttpMessageConverter()),
|
||||||
|
factory.getObject());
|
||||||
|
|
||||||
|
this.servletRequest.setRequestURI("/hello.dataless");
|
||||||
|
this.servletResponse.setStatus(400);
|
||||||
|
|
||||||
|
processor.handleReturnValue("body", this.returnTypeString, this.container, this.request);
|
||||||
|
|
||||||
|
String header = servletResponse.getHeader("Content-Disposition");
|
||||||
|
assertThat(header).isEqualTo("inline;filename=f.txt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void supportsReturnTypeResponseBodyOnType() throws Exception {
|
public void supportsReturnTypeResponseBodyOnType() throws Exception {
|
||||||
Method method = ResponseBodyController.class.getMethod("handle");
|
Method method = ResponseBodyController.class.getMethod("handle");
|
||||||
|
|
@ -724,10 +743,14 @@ public class RequestResponseBodyMethodProcessorTests {
|
||||||
|
|
||||||
String header = servletResponse.getHeader("Content-Disposition");
|
String header = servletResponse.getHeader("Content-Disposition");
|
||||||
if (expectContentDisposition) {
|
if (expectContentDisposition) {
|
||||||
assertThat(header).as("Expected 'Content-Disposition' header. Use case: '" + comment + "'").isEqualTo("inline;filename=f.txt");
|
assertThat(header)
|
||||||
|
.as("Expected 'Content-Disposition' header. Use case: '" + comment + "'")
|
||||||
|
.isEqualTo("inline;filename=f.txt");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
assertThat(header).as("Did not expect 'Content-Disposition' header. Use case: '" + comment + "'").isNull();
|
assertThat(header)
|
||||||
|
.as("Did not expect 'Content-Disposition' header. Use case: '" + comment + "'")
|
||||||
|
.isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.servletRequest = new MockHttpServletRequest();
|
this.servletRequest = new MockHttpServletRequest();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue