Merge branch '5.2.x' into master

This commit is contained in:
Rossen Stoyanchev
2020-09-14 15:43:38 +01:00
3 changed files with 48 additions and 5 deletions

View File

@@ -400,6 +400,25 @@ public class RequestResponseBodyMethodProcessorTests {
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
public void supportsReturnTypeResponseBodyOnType() throws Exception {
Method method = ResponseBodyController.class.getMethod("handle");
@@ -724,10 +743,14 @@ public class RequestResponseBodyMethodProcessorTests {
String header = servletResponse.getHeader("Content-Disposition");
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 {
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();