Browse Source

Protected getContentType in DecoderHttpMessageReader

Issue: SPR-16856
pull/1851/merge
Rossen Stoyanchev 7 years ago
parent
commit
fd946b8157
  1. 10
      spring-web/src/main/java/org/springframework/http/codec/DecoderHttpMessageReader.java
  2. 7
      spring-web/src/main/java/org/springframework/web/client/HttpMessageConverterExtractor.java

10
spring-web/src/main/java/org/springframework/http/codec/DecoderHttpMessageReader.java

@ -93,7 +93,15 @@ public class DecoderHttpMessageReader<T> implements HttpMessageReader<T> { @@ -93,7 +93,15 @@ public class DecoderHttpMessageReader<T> implements HttpMessageReader<T> {
return this.decoder.decodeToMono(message.getBody(), elementType, contentType, hints);
}
private MediaType getContentType(HttpMessage inputMessage) {
/**
* Determine the Content-Type of the HTTP message based on the
* "Content-Type" header or otherwise default to
* {@link MediaType#APPLICATION_OCTET_STREAM}.
* @param inputMessage the HTTP message
* @return the MediaType, possibly {@code null}.
*/
@Nullable
protected MediaType getContentType(HttpMessage inputMessage) {
MediaType contentType = inputMessage.getHeaders().getContentType();
return (contentType != null ? contentType : MediaType.APPLICATION_OCTET_STREAM);
}

7
spring-web/src/main/java/org/springframework/web/client/HttpMessageConverterExtractor.java

@ -120,6 +120,13 @@ public class HttpMessageConverterExtractor<T> implements ResponseExtractor<T> { @@ -120,6 +120,13 @@ public class HttpMessageConverterExtractor<T> implements ResponseExtractor<T> {
"for response type [" + this.responseType + "] and content type [" + contentType + "]");
}
/**
* Determine the Content-Type of the response based on the "Content-Type"
* header or otherwise default to {@link MediaType#APPLICATION_OCTET_STREAM}.
* @param response the response
* @return the MediaType, possibly {@code null}.
*/
@Nullable
protected MediaType getContentType(ClientHttpResponse response) {
MediaType contentType = response.getHeaders().getContentType();
if (contentType == null) {

Loading…
Cancel
Save