opened
FireDrunk
username_0
**Describe the bug**
RequestBody.toString() doesn't provide any usable information

**To Reproduce**
Steps to reproduce the behavior:
1. Create an Interceptor
2. Override the onRequest method
3. Try to log the RequestBody

**Expected behavior**
Something... usable.

**Environmental Data:**
 - Java Version: Adopt OpenJDK 11.0.8.10
 - Version: 3.11.02

**Additional context**
The problem is that it's almost impossible to disect the object. It potentially has things like Multi/Uniparts, or some basic fields.
That's exactly the type of body I want to log. Is there any example on how to log the fields set by the .field() function?
[Interceptor] Logging the RequestBody
issue
created
ryber
username_1
The problem is, a multi-part form potentially has files which may be quite large and are somewhat unknowable without going through the entire process twice (once for the logger and once for the real thing. At the very least you could never log exactly what was sent since the parts and their part ID's would be different. Similarly, other types of bodies will also support binary streams which couldn't be logged (meaningfully). I might be able to produce a simple summary of the body for simple field types, but it's not going to be exactly what is sent over the wire.
comment
created
FireDrunk
username_0
Understandable. I think it might be nice to have a way to 'read' wether that's the case. I've tried doing this with the isMultipart() and the isUnipart() functions, but that doesn't tell me what information is readable afterwards.
Upon looking inside the object I see something like an ApacheRequestBody with a Mode that is set to "BROWSER_COMPATIBLE".

This still doesn't give me any information on what's inside.

I think a function like printNestedFields() and some more isSomething() and hasSomething() functions might come in handy.
comment
created
ryber
username_1
You shouldn't need to look at the mode at at, in fact, looking at any Apache part of unirest is discouraged as future versions may remove it as a dependency. The multiparts will simply return an empty collection if it's not a multipart request. This should do the same thing as above with fewer parts:

```
new Interceptor() {
            @Override
            public void onRequest(HttpRequest<?> request, Config config) {
                request.getBody().ifPresent(b -> {
                    b.multiParts().forEach(part -> {
                        if(part.getPartType().equals(String.class)){
                            System.out.println(part.getName() + "="+ part.getValue());
                        }
                    });
                });
            }
        });
```

I will take this to look into some methods to make logging and inspecting specific fields easier.
comment
created
FireDrunk
username_0
Given example doesn't log anything in my case.
comment
created
ryber
username_1
in 3.11.03 there are a few things that can help.


1. All of the request parts have sane ```toString()``` representations. for example a param part will toString as ```key=value```. Files toString as the file name.
1. the request summary interface which is passed to the interceptors has a ```asString()``` method which will return an approximation of the request suitable for logging. Again, binary data is excluded, and multipart forms will have different part IDs but it will mostly be correct. see https://github.com/Kong/unirest-java/blob/8789e9208d73e9d3c471b90bcd699fd75115f768/unirest/src/test/java/BehaviorTests/BodyLogSummaryTest.java
1. There is now a method to get a body part by name https://github.com/Kong/unirest-java/blob/main/unirest/src/test/java/kong/unirest/BodyTest.java#L33-L42
1. I added a test showing collecting parts from the interceptor: https://github.com/Kong/unirest-java/blob/main/unirest/src/test/java/BehaviorTests/InterceptorTest.java#L162-L179
comment
closed
ryber
username_1
issue