Affects: \
response.setHeader("Content-Type","application/json"); in Filter.
after:
ServletServerHttpResponse:getFirst() can't not get Header when headername is "Content-Type".
because, when response.setHeader("Content-Type","application/json") ,tomcat response have not add Content-Type to header, it's only set contentType,so ServletServerHttpResponse:getFirst() can't not get Header when headername is "Content-Type"
tomcat setHeader code: @Override public void setHeader(String name, String value) {
if (name == null || name.length() == 0 || value == null) {
return;
}
if (isCommitted()) {
return;
}
// Ignore any call from an included servlet
if (included) {
return;
}
char cc=name.charAt(0);
if (cc=='C' || cc=='c') {
if (checkSpecialHeader(name, value)) {
return;
}
}
getCoyoteResponse().setHeader(name, value);
}
issue fix code: if value is null from super.getFirst,then to servletResponse.getContentType();
@Override
@Nullable
public String getFirst(String headerName) {
if (headerName.equalsIgnoreCase(CONTENT_TYPE)) {
// Content-Type is written as an override so check super first
String value = super.getFirst(headerName);
if (value == null) {
value = servletResponse.getContentType();
}
return (value != null ? value : servletResponse.getHeader(headerName));
}
else {
String value = servletResponse.getHeader(headerName);
return (value != null ? value : super.getFirst(headerName));
}
}
Comment From: bclozel
Sorry for the late reply. Instead of suggesting a solution, can you provide a minimal application that we can take a look at?
Comment From: spring-projects-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Comment From: spring-projects-issues
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.