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

How to log request body instead of <multipart>? #273

Closed
mrados7 opened this issue May 24, 2018 · 6 comments
Closed

How to log request body instead of <multipart>? #273

mrados7 opened this issue May 24, 2018 · 6 comments
Assignees

Comments

@mrados7
Copy link

mrados7 commented May 24, 2018

I need to log my request body, but it keeps printing . Body form is "form-data".

@whiskeysierra
Copy link
Collaborator

The default RawRequestFilter delegates to the default BodyReplacer which in turn replaces multi part bodies with the string <multi-part>. If you need to override the default behaviour you need to configure your own RawRequestFilter.

@mrados7
Copy link
Author

mrados7 commented May 24, 2018

Can you give me an example how to make @bean RawRequestFilter cause I'm not sure how to use replaceBody when I need to save that body not replace it with some string. I'm using logbook-spring-boot-starter.

@whiskeysierra
Copy link
Collaborator

That should do the trick.

@Bean
public RawRequestFilter rawRequestFilter() {
    return RawRequestFilter.none();
}

@mrados7
Copy link
Author

mrados7 commented May 24, 2018

Yeah, that's first thing I tried but it shows nothing in log form body.

@whiskeysierra
Copy link
Collaborator

I only read multipart, nothing about form. Ok, I guess you're using the LogbookFilter as part of your filter chain. You're most likely hitting this: https://github.com/zalando/logbook#servlet

The LogbookFilter will, by default, treat requests with a application/x-www-form-urlencoded body not different from any other request, i.e you will see the request body in the logs. The downside of this approach is that you won't be able to use any of the HttpServletRequest.getParameter*(..) methods. See issue #94 for some more details.

As of Logbook 1.5.0, you can now specify one of three strategies that define how Logbook deals with this situation by using the logbook.servlet.form-request system property:

Value Pros Cons
body(default) Body is logged Downstream code can not use getParameter*()
parameter Body is logged (but it's reconstructed from parameters) Downstream code can not use getInputStream()
off Downstream code can decide whether to use getInputStream() or getParameter*() Body is not logged

@mrados7
Copy link
Author

mrados7 commented May 24, 2018

Ok thank you, understood :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants