Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
/**
* {@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
* or controller method annotations.
*
Expand All @@ -58,14 +59,12 @@ public class EncoderHttpMessageWriter<T> implements HttpMessageWriter<T> {

private static final Log logger = HttpLogging.forLogName(EncoderHttpMessageWriter.class);


private final Encoder<T> encoder;

private final List<MediaType> mediaTypes;

private final @Nullable MediaType defaultMediaType;


/**
* Create an instance wrapping the given {@link Encoder}.
*/
Expand All @@ -89,7 +88,6 @@ private static void initLogger(Encoder<?> encoder) {
return mediaTypes.stream().filter(MediaType::isConcrete).findFirst().orElse(null);
}


/**
* Return the {@code Encoder} of this writer.
*/
Expand Down Expand Up @@ -131,6 +129,8 @@ public Mono<Void> write(Publisher<? extends T> inputStream, ResolvableType eleme
}))
.flatMap(buffer -> {
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
Comment on lines +132 to +133
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is inaccurate and misleading. The code at line 134 unconditionally sets the Content-Length header for all HTTP messages (both requests and responses), not just GET requests. Additionally, there is no check for whether the value is greater than 0 - it always sets it to the buffer's readable byte count. The comment should either be removed or corrected to accurately describe what the code does: "Set Content-Length header based on the buffer size".

Suggested change
// Only set Content-Length header for GET requests if value > 0
// This prevents sending unnecessary headers for other request types
// Set Content-Length header based on the buffer size

Copilot uses AI. Check for mistakes.
message.getHeaders().setContentLength(buffer.readableByteCount());
return message.writeWith(Mono.just(buffer)
.doOnDiscard(DataBuffer.class, DataBufferUtils::release));
Expand Down Expand Up @@ -200,7 +200,6 @@ private boolean matchParameters(MediaType streamingMediaType, MediaType mediaTyp
return true;
}


// Server side only...

@Override
Expand Down