Skip to content

Commit

Permalink
null check for content length (#83)
Browse files Browse the repository at this point in the history
---------
Co-authored-by: Kinshuk Bairagi <[email protected]>
  • Loading branch information
ajay-jalgaonkar authored Aug 7, 2024
1 parent e5fcfb5 commit 9655952
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;
import java.util.Optional;

/**
* Implements an HTTP filter for logging access requests. This filter captures and logs
Expand Down Expand Up @@ -81,8 +82,9 @@ public void doProcessResponse(ServletResponse response) {
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
if (isSuccess(httpServletResponse.getStatus())) {
// 2xx response
accessLogContextBuilder.contentLength(Integer.valueOf(httpServletResponse
.getHeader(HttpHeaderNames.CONTENT_LENGTH.toString())));
int contentLength = Optional.ofNullable(httpServletResponse.getHeader(HttpHeaderNames.CONTENT_LENGTH.toString()))
.map(Integer::parseInt).orElse(0);
accessLogContextBuilder.contentLength(contentLength);
} else {
// non-2xx response
accessLogContextBuilder.contentLength(0);
Expand Down

0 comments on commit 9655952

Please sign in to comment.