okhttp icon indicating copy to clipboard operation
okhttp copied to clipboard

HttpLoggingInterceptor with Level.BODY blocks SSE from reading response

Open alextcn opened this issue 8 years ago • 3 comments

The problem is that SSE doesn't work with HttpLoggingInterceptor that have Level.BODY. Interceptor with other levels are working as expected.

HttpLoggingInterceptor with Level.BODY is not allowing RealEventSource to read response body byte by byte. It looks like interceptor is trying to buffer the entire response body which is not ready until request is done. Therefore Callback.onResponse in RealEventSource doesn't called, response events can't be parsed and passed to EventSourceListener.

The solution could be ignoring response body in HttpLoggingInterceptor for Content-Type: text/event-stream, reading response body line by line or just an explicit warning of not using Level.BODY with SEE in documentation.

Changing log level from Level.BODY for SSE client wouldn't be the best solution because it will also disable logging a body for regular HTTP requests for this client instance.

alextcn avatar Oct 01 '18 14:10 alextcn

Want to send a PR for this?

JakeWharton avatar Oct 01 '18 19:10 JakeWharton

I think we wanna change Level.BODY to do streaming-logging, not buffer-everything logging.

swankjesse avatar Oct 02 '18 00:10 swankjesse

Won't fix. We have a minimal fix attitude to HttpLoggingInterceptor. It deserves it's own github library.

yschimke avatar Mar 29 '20 17:03 yschimke