Skip to content

Commit

Permalink
add logging in preconnection hook
Browse files Browse the repository at this point in the history
  • Loading branch information
anuvedverma committed Jul 2, 2024
1 parent b145513 commit 1ce2104
Showing 1 changed file with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ protected String rewriteTarget(HttpServletRequest request) {
*/
public void preConnectionHook(HttpServletRequest request, Request proxyRequest) {
// you may override it.

// [sev-16337] with a 10% probably, log the request headers for debugging
if (Math.random() < 0.10) {
log.debug("(preConnectionHook) Request URL: {} , request URI {} , servlet path {} ,"
+ "toString {}, getContentLength {}, getRequestHeaderSize {}, requestHeaders {}",
request.getRequestURL(), request.getRequestURI(), request.getServletPath(),
request.toString(), request.getContentLength(), getRequestHeaderSize(request),
errorLogHeaders(request));
}
}

/**
Expand All @@ -60,12 +69,12 @@ protected void postConnectionHook(
request.getRequestURL());
}
response.getOutputStream().write(buffer, offset, length);
// [sev-16337] with a 1% probably, log the request and response headers
// [sev-16337] with a 10% probably, log the request and response headers
// and size for debugging
if (Math.random() < 0.01) {
log.debug("Request URL: {} , request URI {} , servlet path {} ,"
+ "toString {}, getContentLength {}, getRequestHeaderSize {}, getResponseHeaderSize {},
requestHeaders {}, responseHeaders {}",
if (Math.random() < 0.10) {
log.debug("(postConnectionHook - success) Request URL: {} , request URI {} , servlet path {} ,"
+ "toString {}, getContentLength {}, getRequestHeaderSize {}, getResponseHeaderSize {}, "
+ "requestHeaders {}, responseHeaders {}",
request.getRequestURL(), request.getRequestURI(), request.getServletPath(),
request.toString(), request.getContentLength(), getRequestHeaderSize(request),
getResponseHeaderSize(response), errorLogHeaders(request),
Expand All @@ -74,9 +83,9 @@ protected void postConnectionHook(

callback.succeeded();
} catch (Throwable var9) {
log.error("Exception occurred while processing request URL: {} , request URI {} ,"
+ " servlet path {} , toString {}, getContentLength {}, getRequestHeaderSize {},"
+ "getResponseHeaderSize {}, requestHeaders {}, responseHeaders {}",
log.error("(postConnectionHook - failed) Exception occurred while processing request URL: {} , "
+ "request URI {} , servlet path {} , toString {}, getContentLength {}, "
+ "getRequestHeaderSize {}, getResponseHeaderSize {}, requestHeaders {}, responseHeaders {}",
request.getRequestURL(), request.getRequestURI(), request.getServletPath(),
request.toString(), request.getContentLength(), getRequestHeaderSize(request),
getResponseHeaderSize(response), errorLogHeaders(request),
Expand Down

0 comments on commit 1ce2104

Please sign in to comment.