diff --git a/spring-web/src/main/java/org/springframework/http/codec/DecoderHttpMessageReader.java b/spring-web/src/main/java/org/springframework/http/codec/DecoderHttpMessageReader.java index 752d2e895a..073c097220 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/DecoderHttpMessageReader.java +++ b/spring-web/src/main/java/org/springframework/http/codec/DecoderHttpMessageReader.java @@ -93,7 +93,15 @@ public class DecoderHttpMessageReader implements HttpMessageReader { 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); } diff --git a/spring-web/src/main/java/org/springframework/web/client/HttpMessageConverterExtractor.java b/spring-web/src/main/java/org/springframework/web/client/HttpMessageConverterExtractor.java index 8cbd20b797..1315f67cd7 100644 --- a/spring-web/src/main/java/org/springframework/web/client/HttpMessageConverterExtractor.java +++ b/spring-web/src/main/java/org/springframework/web/client/HttpMessageConverterExtractor.java @@ -120,6 +120,13 @@ public class HttpMessageConverterExtractor implements ResponseExtractor { "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) {