Skip to content

Commit

Permalink
Merge pull request #2 from Kerosene-Labs/feat/1
Browse files Browse the repository at this point in the history
Add implicit `Content-Length` if `content` is given in a `HttpResponse`
  • Loading branch information
hlafaille authored Aug 8, 2024
2 parents 6ab2850 + 28656c8 commit 634c86e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/main/java/io/kerosenelabs/kindling/HttpResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ public class HttpResponse {
this.httpStatus = builder.httpStatus;
this.headers = builder.headers;
this.content = builder.content;

// implicitly calculate Content-Length
if (content != null) {
headers.put("Content-Length", Integer.toString(content.getBytes().length));
}
}

public String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public enum HttpStatus {
OK(200, "OK"),
CREATED(201, "Created"),
NO_RESPONSE(204, "No Response"),
NO_CONTENT(204, "No Content"),
BAD_REQUEST(400, "Bad Request"),
NOT_FOUND(404, "Not Found"),
INTERNAL_SERVER_ERROR(500, "Internal Server Error");
Expand Down

0 comments on commit 634c86e

Please sign in to comment.