Protected getContentType in DecoderHttpMessageReader

Issue: SPR-16856
This commit is contained in:
Rossen Stoyanchev
2018-06-05 16:23:21 -04:00
parent 42b4a2feef
commit fd946b8157
2 changed files with 16 additions and 1 deletions

View File

@@ -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);
}

View File

@@ -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) {