Skip to content

Commit

Permalink
Merge pull request #1177 from scireum/feature/jvo/SIRI-721-Content-Le…
Browse files Browse the repository at this point in the history
…ngth

Fix: Content-Length
  • Loading branch information
jakobvogel authored Feb 24, 2023
2 parents 7e3d714 + 7991e6d commit 8be2de2
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/main/java/sirius/web/http/Response.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,14 @@ protected Response(WebContext webContext) {
protected DefaultFullHttpResponse createFullResponse(HttpResponseStatus status, boolean keepalive, ByteBuf buffer) {
DefaultFullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, status, buffer);
setupResponse(status, keepalive, response);
response.headers().set(HttpHeaderNames.CONTENT_LENGTH, buffer.readableBytes());

// The user may have manually set a content-length, for instance when
// responding to a HEAD request. In such cases, we trust the user that
// the value is correct and don't change it.
if (!response.headers().contains(HttpHeaderNames.CONTENT_LENGTH)) {
response.headers().set(HttpHeaderNames.CONTENT_LENGTH, buffer.readableBytes());
}

return response;
}

Expand Down

0 comments on commit 8be2de2

Please sign in to comment.