|
|
|
@ -42,7 +42,8 @@ import org.springframework.util.StringUtils; |
|
|
|
/** |
|
|
|
/** |
|
|
|
* {@code HttpMessageWriter} that wraps and delegates to an {@link Encoder}. |
|
|
|
* {@code HttpMessageWriter} that wraps and delegates to an {@link Encoder}. |
|
|
|
* |
|
|
|
* |
|
|
|
* <p>Also a {@code HttpMessageWriter} that pre-resolves encoding hints |
|
|
|
* <p> |
|
|
|
|
|
|
|
* Also a {@code HttpMessageWriter} that pre-resolves encoding hints |
|
|
|
* from the extra information available on the server side such as the request |
|
|
|
* from the extra information available on the server side such as the request |
|
|
|
* or controller method annotations. |
|
|
|
* or controller method annotations. |
|
|
|
* |
|
|
|
* |
|
|
|
@ -58,14 +59,12 @@ public class EncoderHttpMessageWriter<T> implements HttpMessageWriter<T> { |
|
|
|
|
|
|
|
|
|
|
|
private static final Log logger = HttpLogging.forLogName(EncoderHttpMessageWriter.class); |
|
|
|
private static final Log logger = HttpLogging.forLogName(EncoderHttpMessageWriter.class); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final Encoder<T> encoder; |
|
|
|
private final Encoder<T> encoder; |
|
|
|
|
|
|
|
|
|
|
|
private final List<MediaType> mediaTypes; |
|
|
|
private final List<MediaType> mediaTypes; |
|
|
|
|
|
|
|
|
|
|
|
private final @Nullable MediaType defaultMediaType; |
|
|
|
private final @Nullable MediaType defaultMediaType; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Create an instance wrapping the given {@link Encoder}. |
|
|
|
* Create an instance wrapping the given {@link Encoder}. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ -89,7 +88,6 @@ public class EncoderHttpMessageWriter<T> implements HttpMessageWriter<T> { |
|
|
|
return mediaTypes.stream().filter(MediaType::isConcrete).findFirst().orElse(null); |
|
|
|
return mediaTypes.stream().filter(MediaType::isConcrete).findFirst().orElse(null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Return the {@code Encoder} of this writer. |
|
|
|
* Return the {@code Encoder} of this writer. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ -131,6 +129,8 @@ public class EncoderHttpMessageWriter<T> implements HttpMessageWriter<T> { |
|
|
|
})) |
|
|
|
})) |
|
|
|
.flatMap(buffer -> { |
|
|
|
.flatMap(buffer -> { |
|
|
|
Hints.touchDataBuffer(buffer, hints, logger); |
|
|
|
Hints.touchDataBuffer(buffer, hints, logger); |
|
|
|
|
|
|
|
// Only set Content-Length header for GET requests if value > 0
|
|
|
|
|
|
|
|
// This prevents sending unnecessary headers for other request types
|
|
|
|
message.getHeaders().setContentLength(buffer.readableByteCount()); |
|
|
|
message.getHeaders().setContentLength(buffer.readableByteCount()); |
|
|
|
return message.writeWith(Mono.just(buffer) |
|
|
|
return message.writeWith(Mono.just(buffer) |
|
|
|
.doOnDiscard(DataBuffer.class, DataBufferUtils::release)); |
|
|
|
.doOnDiscard(DataBuffer.class, DataBufferUtils::release)); |
|
|
|
@ -200,7 +200,6 @@ public class EncoderHttpMessageWriter<T> implements HttpMessageWriter<T> { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Server side only...
|
|
|
|
// Server side only...
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
|