Skip to content

Commit

Permalink
Merge pull request #892 from apache/feature/WW-5401-logging
Browse files Browse the repository at this point in the history
[WW-5401] Improves logging around wrapping request and detecting multipart request
  • Loading branch information
lukaszlenart authored Mar 11, 2024
2 parents 6648cbd + ac6c88a commit e08f637
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -986,10 +986,12 @@ private void applyEncoding(HttpServletResponse response, String encoding) {
public HttpServletRequest wrapRequest(HttpServletRequest request) throws IOException {
// don't wrap more than once
if (request instanceof StrutsRequestWrapper) {
LOG.debug("Request already wrapped with: {}", StrutsRequestWrapper.class.getSimpleName());
return request;
}

if (isMultipartSupportEnabled(request) && isMultipartRequest(request)) {
LOG.debug("Wrapping multipart request with: {}", MultiPartRequestWrapper.class.getSimpleName());
request = new MultiPartRequestWrapper(
getMultiPartRequest(),
request,
Expand All @@ -998,6 +1000,7 @@ public HttpServletRequest wrapRequest(HttpServletRequest request) throws IOExcep
disableRequestAttributeValueStackLookup
);
} else {
LOG.debug("Wrapping request using: {}", StrutsRequestWrapper.class.getSimpleName());
request = new StrutsRequestWrapper(request, disableRequestAttributeValueStackLookup);
}

Expand All @@ -1012,6 +1015,7 @@ public HttpServletRequest wrapRequest(HttpServletRequest request) throws IOExcep
* @since 2.5.11
*/
protected boolean isMultipartSupportEnabled(HttpServletRequest request) {
LOG.debug("Support for multipart request is enabled: {}", multipartSupportEnabled);
return multipartSupportEnabled;
}

Expand All @@ -1026,9 +1030,12 @@ protected boolean isMultipartRequest(HttpServletRequest request) {
String httpMethod = request.getMethod();
String contentType = request.getContentType();

return REQUEST_POST_METHOD.equalsIgnoreCase(httpMethod) &&
contentType != null &&
multipartValidationPattern.matcher(contentType.toLowerCase(Locale.ENGLISH)).matches();
boolean isPostRequest = REQUEST_POST_METHOD.equalsIgnoreCase(httpMethod);
boolean isProperContentType = contentType != null && multipartValidationPattern.matcher(contentType.toLowerCase(Locale.ENGLISH)).matches();

LOG.debug("Validating if this is a proper Multipart request. Request is POST: {} and ContentType matches pattern ({}): {}",
isPostRequest, multipartValidationPattern, isProperContentType);
return isPostRequest && isProperContentType;
}

/**
Expand Down

0 comments on commit e08f637

Please sign in to comment.