-
Notifications
You must be signed in to change notification settings - Fork 263
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
logbook does not print request body when method=POST and header=x-www-form-urlencoded #169
Comments
Can you be sure you're not hitting this issue? https://github.com/zalando/logbook#known-issues |
Yes, exactly it is . I will read #94 carefully. |
I'd assume that Spring is calling |
When handle the Call Stack is :
|
Ok, good find. As stated in #94 I don't see a way to solve this completely. |
After read #94,i find the key concern is logbook can not judge parameter from query string or body. but i don't care, if HTTP method is |
I have overwrite CompleteCurlHttpLogFormatter.java
So is FormBodyConstructs.java public class FormBodyConstructs {
public static boolean isRemoteFormRequest(Object message){
if (!(message instanceof FilteredHttpRequest)) {
return false;
}
FilteredHttpRequest request = (FilteredHttpRequest)message;
HttpRequest httpRequest = request.delegate();
String method = request.getMethod();
Map<String, List<String>> headers = request.getHeaders();
boolean containsHeader = headers.entrySet().stream().filter(entry -> {
boolean hasHeader = entry.getKey().equalsIgnoreCase("Content-Type");
boolean isFormHeader = entry.getValue().stream().filter(v -> v.contains("application/x-www-form-urlencoded")).findAny().isPresent();
return hasHeader && isFormHeader;
}).findAny().isPresent();
if (httpRequest instanceof HttpServletRequest && method.equalsIgnoreCase("POST") && containsHeader) {
return true;
}
return false;
}
public static String getFormBody(Object message){
FilteredHttpRequest filteredHttpRequest = (FilteredHttpRequest)message;
HttpServletRequestWrapper requestWrapper = (HttpServletRequestWrapper)(filteredHttpRequest.delegate());
ServletRequest request = requestWrapper.getRequest();
Map<String, String[]> map = request.getParameterMap();
StringBuilder body = new StringBuilder();
map.forEach((k,v) ->{
Stream.of(v).forEach(item -> body.append(k + "=" + item + "&"));
});
String end = StringUtils.removeEnd(body.toString(), "&");
return end;
}
} It is really unclean. 😄 |
That is the problem. As stated in #94, we can't use that method. As soon as any party uses either this method or the underlying inputstream, then the other method will not work anymore. Right now we always use the inputstream. If somebody used getParameter before we don't see any body (as shown in this issue). We either live with that (as stated in the known issues) or we make it configurable whether in case of POST + application/x-www-form-urlencoded we:
|
|
That is true, but by doing so we make a decision and that might not be in the best interest of the application code running after us. But checking whether the request was We would break anybody who intends to read the body (via |
You can expose a config option about |
Logbook is an utility library which has to serve two requirements: be useful and be not invasive. |
I discussed this with @AlexanderYastrebov and I'll just leave a snapshot of our whiteboard for my future self. |
The bug project i have upload
https://github.com/wyzssw/logbookbug
CURL FORMAT:
HTTP FORMAT:
The text was updated successfully, but these errors were encountered: