-
Notifications
You must be signed in to change notification settings - Fork 256
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
HttpLogFormatter makes multipart requests unprocessable in Spring #1321
Comments
My guess would be that we're consuming the request body incorrectly or rather that we don't preserve the original one. |
The problem is that Spring resolves multipart arguments with
Spring Boot version: 2.5.1
|
In order to prioritize the support for Logbook, we would like to check whether the old issues are still relevant.
|
This issue has automatically been closed due to no activities. If the issue still exists in the latest version of the Logbook, please feel free to re-open it. |
When trying to log a multipart request with a
HttpLogFormatter
the request body is logged correctly, but when the request eventually reaches Spring'sMultipartResolver
, it cannot be resolved anymore and aMissingServletRequestPartException
is thrown. The behavior in Spring seems similar to #637, but it is reproducible on the latest Logbook version 2.14.0.Description
I encountered this behavior when I tried to log the body of a multipart request with Logbook. By default, there is a
BodyReplacer
in place which just replaces the body with<multipart>
, so I disabled the existingRequestFilter
. Requests would then be logged inside of a customSink
which uses the JsonHttpLogFormatter to format the request, but it is also reproducible with theDefaultHttpLogFormatter
.Code has been ported from Kotlin to Java for the sake of this report - I hope it's compilable, but at the very least it should be understandable.
When I instead just put a static String inside the
RawJsonAppendingMarker
, the request comes out intact, so the issue seems to be related to calling the HttpLogFormatter.Expected Behavior
When formatting a request with a
HttpLogFormatter
, the request should afterwards still work as expected when it reaches the controller.Actual Behavior
When formatting a request with a
HttpLogFormatter
, Spring will not be able to resolve the request afterwards and throw an exception.Possible Fix
Not sure if that really counts a fix, it's more of a nice-to-have. What I ended up doing to solve the problem is writing my own
HandlerInterceptor
which logs the request (which is ajavax.servlet.http.HttpServletRequest
here) as the individual parts. If the request would be resolved by Logbook, maybe instead of being restricted to just logging thebody
, the user could be able to log individual parts through Filters (e.g. log text, but don't log files).Steps to Reproduce
either
or
RestController
in Spring which takes a multipart request through POST e.g.public void create(@RequestPart("text") String text) { }
RequestFilter
by settingRequestFilter.none()
to avoid replacement of the body.HttpLogFormatter.format
on the request and precorrelationContext
I was unable to log the body of the multipart request in order to understand whether or not it was correctly formatted and had the correct headers and parts.
Your Environment
The text was updated successfully, but these errors were encountered: