amitshekhariitbhu / Fast-Android-Networking

🚀 A Complete Fast Android Networking Library that also supports HTTP/2 🚀
https://outcomeschool.com
Apache License 2.0
5.68k stars 956 forks source link

HttpLoggingInterceptor don't add a response Body ? #507

Open GuillianDrouin opened 4 years ago

GuillianDrouin commented 4 years ago

Hello, I created a module api client with your lib. In my gradle implementation 'com.amitshekhar.android:android-networking:1.0.2'

For my dev, I use this line after initialization "AndroidNetworking.initialize(getApplicationContext()" : AndroidNetworking.enableLogging(HttpLoggingInterceptor.Level.BODY)

My api client works well !

But in my release app, this line as changed to : AndroidNetworking.enableLogging(HttpLoggingInterceptor.Level.NONE)

My app « freeze » after first call, because my api client listener not send success or error.

After search the problem, I saw a AndroidNetworking.enableLogging create a httpClient with HttpLoggingInterceptor. And if the level as not a BODY, I do not pass to line 246 : https://github.com/amitshekhariitbhu/Fast-Android-Networking/blob/2a72ef2694c55d8391c553400c0ae54c9d7e5038/android-networking/src/main/java/com/androidnetworking/interceptors/HttpLoggingInterceptor.java#L246

In my case, if this lines as not execute :

BufferedSource source = responseBody.source();
source.request(Long.MAX_VALUE);

The OkHttpResponseListener launch « onResponse(Response response) » with response.body() null.

On the other side, if execute, works well !

I created a class « NoLogInterceptor » with juste this code

public class NoLogInterceptor extends HttpLoggingInterceptor {

    @Override
    public Response intercept(Chain chain) throws IOException {
        Request request = chain.request();
        Response response;
        response = chain.proceed(request);
        ResponseBody responseBody = response.body();

        BufferedSource source = responseBody.source();
        source.request(Long.MAX_VALUE); // Buffer the entire body.

        return response;
    }
}

It’s works well !

Whats the problem ? Thank !

GuillianDrouin commented 4 years ago

No news ? 😥

zigic88 commented 4 years ago

@GuillianDrouin Have you try override that HttpLogginInterceptor in your custom Oktthp than init in your FAN initialization