ServletServerHttpRequest.getHeaders() ignores invalid content type
Issue: SPR-14309
This commit is contained in:
@@ -37,6 +37,7 @@ import javax.servlet.http.HttpServletRequest;
|
|||||||
|
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
|
import org.springframework.http.InvalidMediaTypeException;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.LinkedCaseInsensitiveMap;
|
import org.springframework.util.LinkedCaseInsensitiveMap;
|
||||||
@@ -104,6 +105,7 @@ public class ServletServerHttpRequest implements ServerHttpRequest {
|
|||||||
public HttpHeaders getHeaders() {
|
public HttpHeaders getHeaders() {
|
||||||
if (this.headers == null) {
|
if (this.headers == null) {
|
||||||
this.headers = new HttpHeaders();
|
this.headers = new HttpHeaders();
|
||||||
|
|
||||||
for (Enumeration<?> headerNames = this.servletRequest.getHeaderNames(); headerNames.hasMoreElements();) {
|
for (Enumeration<?> headerNames = this.servletRequest.getHeaderNames(); headerNames.hasMoreElements();) {
|
||||||
String headerName = (String) headerNames.nextElement();
|
String headerName = (String) headerNames.nextElement();
|
||||||
for (Enumeration<?> headerValues = this.servletRequest.getHeaders(headerName);
|
for (Enumeration<?> headerValues = this.servletRequest.getHeaders(headerName);
|
||||||
@@ -112,7 +114,9 @@ public class ServletServerHttpRequest implements ServerHttpRequest {
|
|||||||
this.headers.add(headerName, headerValue);
|
this.headers.add(headerName, headerValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// HttpServletRequest exposes some headers as properties: we should include those if not already present
|
// HttpServletRequest exposes some headers as properties: we should include those if not already present
|
||||||
|
try {
|
||||||
MediaType contentType = this.headers.getContentType();
|
MediaType contentType = this.headers.getContentType();
|
||||||
if (contentType == null) {
|
if (contentType == null) {
|
||||||
String requestContentType = this.servletRequest.getContentType();
|
String requestContentType = this.servletRequest.getContentType();
|
||||||
@@ -132,6 +136,11 @@ public class ServletServerHttpRequest implements ServerHttpRequest {
|
|||||||
this.headers.setContentType(newContentType);
|
this.headers.setContentType(newContentType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (InvalidMediaTypeException ex) {
|
||||||
|
// Ignore: simply not exposing an invalid content type in HttpHeaders...
|
||||||
|
}
|
||||||
|
|
||||||
if (this.headers.getContentLength() < 0) {
|
if (this.headers.getContentLength() < 0) {
|
||||||
int requestContentLength = this.servletRequest.getContentLength();
|
int requestContentLength = this.servletRequest.getContentLength();
|
||||||
if (requestContentLength != -1) {
|
if (requestContentLength != -1) {
|
||||||
@@ -139,6 +148,7 @@ public class ServletServerHttpRequest implements ServerHttpRequest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.headers;
|
return this.headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user