Fast-Android-Networking icon indicating copy to clipboard operation
Fast-Android-Networking copied to clipboard

HttpLoggingInterceptor don't add a response Body ?

Open GuillianDrouin opened this issue 5 years ago • 2 comments
trafficstars

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 avatar May 19 '20 14:05 GuillianDrouin

No news ? 😥

GuillianDrouin avatar Sep 04 '20 14:09 GuillianDrouin

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

zigic88 avatar Sep 04 '20 19:09 zigic88