facebook / stetho

Stetho is a debug bridge for Android applications, enabling the powerful Chrome Developer Tools and much more.
http://facebook.github.io/stetho/
MIT License
12.68k stars 1.13k forks source link

All Responses are not logged in Network tab via chain.proceed(request) in okhttp3 #368

Closed Aexyn closed 8 years ago

Aexyn commented 8 years ago

I am trying to integrate Okhttp3 in my chat app with new StethoInterceptor. When I send some message through App, That message is visible in Header Tab of the request in Network window of Chrome DevTool. But When I receive some message, It is not visible.

However when I do the same with this class:

class LoggingInterceptor implements Interceptor {
        @SuppressLint("DefaultLocale")
        @Override public Response intercept(Interceptor.Chain chain) throws IOException {
            Request request = chain.request();

            long t1 = System.nanoTime();
            Log.d(TAG, "intercept: "+String.format("Sending request %s on %s%n%s%n%s%n",
                    request.url(), chain.connection(), request.headers(),request.body().toString()));

            Response response = chain.proceed(request);

            long t2 = System.nanoTime();
            Log.d(TAG, "intercept: "+ String.format("Received response for %s in %.1fms%n%s%n%s%n",
                    response.request().url(), (t2 - t1) / 1e6d, response.headers(),response.body().string()));

            return response;
        }
    }

It Works for both incoming and outgoing calls.

It might be possible that there is a switch to activate logging incoming connections that I might not know. Please Help

jasta commented 8 years ago

HTTP 1.x is a request/response protocol that involves the client initiating a connection to a server and making a request, then expecting a reply. There is no concept in this system of the server then issueing a request to the client, or a server "connecting back" to the client. You would have to be hosting a web server in your application for this to occur.

That said, if you are using HTTP 2 features, you can indeed have server push messages that don't work in the normal HTTP sense though I strongly doubt that okhttp's network interceptor properly supports this concept based on its API.

Can you please be more (much more) specific about how your protocol actually works so we can try to figure out what Stetho can do to help?

jasta commented 8 years ago

Closing due to inactivity. Still require an answer to my questions to resolve...