Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WW-5401] Improves logging around wrapping request and detecting multipart request #892

Merged
merged 3 commits into from
Mar 11, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
lukaszlenart marked this conversation as resolved.
Show resolved Hide resolved
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 proper Multipart request. Request is POST: {} and ContentType matches pattern ({}): {}",
lukaszlenart marked this conversation as resolved.
Show resolved Hide resolved
isPostRequest, multipartValidationPattern, isProperContentType);
return isPostRequest && isProperContentType;
}

/**
Expand Down