-
Notifications
You must be signed in to change notification settings - Fork 261
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 POST parameters? #94
Comments
Thanks for bringing this up! First, just to verify: You are missing post parameters on incoming requests going towards your service, right? Because I think (haven't verified) that it should actually work for outgoing requests to other services. I'll try to run some tests, so for now the following is just what I remember and what I think how it works: The Servlet spec handles /**
* Returns a java.util.Map of the parameters of this request.
*
* <p>Request parameters are extra information sent with the request.
* For HTTP servlets, parameters are contained in the query string or
* posted form data.
*
* @return an immutable java.util.Map containing parameter names as
* keys and parameter values as map values. The keys in the parameter
* map are of type String. The values in the parameter map are of type
* String array.
*/
public Map<String, String[]> getParameterMap(); TL;DR: For HTTP servlets, parameters are contained in the query string or posted form data That means what we get is a big pile of parameters without knowing where they came from. We have several options now:
|
Other option would be to add explicit parameters field. |
I did take another look at this and found this part of the javadoc of HttpServletRequest.getParameter(String):
See also http://stackoverflow.com/a/10212328/232539
Basically I don't see any way to make this work in a clean way. Right now we are consuming the whole input stream. I'd assume that breaks everyone who uses |
Can we skip reading body in this case and substitute its value with getParametersMap? |
So for The main goal is not to break underlying servlets. |
It depends. That decision is usually left for the servlet to make. If the servlet correctly assumes it's in charge and wants to read the input stream directly (without using getParameter*) then we broke it. |
My idea would be to allow the following behaviours to be configurable:
Users of the library could then choose to use the strategy that fits them best. I agree with the multipart suggestion. |
I would prefer to log the original request instead of reconstructing it, even if it would mean having to do the parameter parsing ourselves. So the configurable behaviour could be:
|
Thinking about this some more, logic in the application depends on the parsed parameter map, not the original body, so maybe it is ok to log these parameters instead. I still would prefer not try to reconstruct the original body. This is not possible anyway in case parameters come from both query string and post body. Maybe a better solution would be to
And I just saw that Alexander already proposed something similar before. |
To be fair, conceptually and by design Logbook is doing exactly that. Everything we log, request line, headers and body, all of that is only reconstructed from what the underlying implementation is giving us. There could be defaults kicking in that we receive that we're never actually send by the client. Furthermore, since we are running in a filter (at least in the servlet part) we are already running behind something else (e.g. Tracer which adds a header to the request that we also log!). The same applies to the HTTP client integration where we're running as an interceptor after potentially many different others. Coming from that point of view I'd say it's still ok to reconstruct the body for POST parameters. It has the nice benefit that we don't need any special handling or additional fields in our internal API. It's just a body (as it would be on the wire). |
I added a test to verify that we do in fact consume the body right now and log the parameters as such: {
"origin": "remote",
"type": "request",
"correlation": "2d66e4bc-9a0d-11e5-a84c-1f39510f0d6b",
"protocol": "HTTP/1.1",
"sender": "127.0.0.1",
"method": "POST",
"path": "http://example.org/test",
"headers": {
"Content-Type": ["application/x-www-form-urlencoded"]
},
"body": "name=Alice&age=7.5"
} I'll close the issue for now, as this is good enough for us. Users are encouraged to re-open this or create a new issue if needed. An idea to solve this would be to delay the logging of the request until the servlet behind the filter actually either consumes the input stream or uses one of the |
I'm using org.zalando:logbook-spring-boot-starter:1.0.0-RC1.
When content-type is application/x-www-form-urlencoded, logbook can't print post parameters.
So is there any configuration show the parameters?
The text was updated successfully, but these errors were encountered: