square / okhttp

Square’s meticulous HTTP client for the JVM, Android, and GraalVM.
https://square.github.io/okhttp/
Apache License 2.0
45.87k stars 9.16k forks source link

LoggingInterceptor doesn't log iCalendar files, WebDAV XML response bodies etc. because they are considered binary #2579

Closed rfc2822 closed 8 years ago

rfc2822 commented 8 years ago

Since okhttp 3.3, HttpLoggingInterceptor makes a difference between plain-text and binary bodies and doesn't log binary bodies.

However, I want HttpLoggingInterceptor to always log the bodies. Requested iCalendar (plain text) files, WebDAV XML response bodies etc. are considered to be binary be the interceptor and thus dismissed for logging. Extending HttpLoggingInterceptor and overwriting isPlaintext() is not possible because it's static.

What's the intended way to make sure HttpLoggingInterceptor is always logging the bodies?

JakeWharton commented 8 years ago

You can copy/paste it into your project and modify to your needs. The provided interceptor isn't designed to solve everyone's use-case, more just the common ones.

swankjesse commented 8 years ago

I’m surprised that these files are considered to be binary. Could you paste a gist with a sample file?

rfc2822 commented 8 years ago

Unfortunately, Github doesn't allow to attach .vcf or .ics files. So I have zipped the files: sample.zip

I guess they're considered binary because they contain control characters within the first 16 characters?

If I remember correctly, I have also seen WebDAV XML responses which were treated binary, probably for the same reason.

What about making isPlaintext() non-static, so that users can overwrite it?

swankjesse commented 8 years ago

Turns out it’s just the newline characters. I’ll get this fixed and cut a 3.3.1. Sigh.