Lenient treatment of malformed Accept header for @ExceptionHandler
Closes gh-24539
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -209,7 +209,6 @@ public class HttpEntityMethodProcessorTests {
|
||||
|
||||
@Test // SPR-13423
|
||||
public void handleReturnValueWithETagAndETagFilter() throws Exception {
|
||||
|
||||
String eTagValue = "\"deadb33f8badf00d\"";
|
||||
String content = "body";
|
||||
|
||||
@@ -242,6 +241,25 @@ public class HttpEntityMethodProcessorTests {
|
||||
assertThat(this.servletResponse.getContentAsString()).isEqualTo(content);
|
||||
}
|
||||
|
||||
@Test // gh-24539
|
||||
public void handleReturnValueWithMalformedAcceptHeader() throws Exception {
|
||||
webRequest.getNativeRequest(MockHttpServletRequest.class).addHeader("Accept", "null");
|
||||
|
||||
List<HttpMessageConverter<?>>converters = new ArrayList<>();
|
||||
converters.add(new ByteArrayHttpMessageConverter());
|
||||
converters.add(new StringHttpMessageConverter());
|
||||
|
||||
Method method = getClass().getDeclaredMethod("handle");
|
||||
MethodParameter returnType = new MethodParameter(method, -1);
|
||||
ResponseEntity<String> returnValue = ResponseEntity.badRequest().body("Foo");
|
||||
|
||||
HttpEntityMethodProcessor processor = new HttpEntityMethodProcessor(converters);
|
||||
processor.handleReturnValue(returnValue, returnType, mavContainer, webRequest);
|
||||
|
||||
assertThat(servletResponse.getStatus()).isEqualTo(400);
|
||||
assertThat(servletResponse.getHeader("Content-Type")).isNull();
|
||||
assertThat(servletResponse.getContentAsString()).isEmpty();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private void handle(HttpEntity<List<SimpleBean>> arg1, HttpEntity<SimpleBean> arg2) {
|
||||
|
||||
Reference in New Issue
Block a user