paul_h
paul_h

Reputation: 2051

How to setup OkHttp to request gzipped resources and NOT un-gzip them

I'm looking at new OkHttpClient.Builder() to see whether there's a setting that would allow me to do 'raw' GETs of resources and then get the compressed bytes for that resource in the response. As far as I can see OkHttp transparently ungzips payloads. I can't see a way of initializing OkHttpClient to not do that. I've tried googling for "gzip OkHttpClient.Builder" and I get a bunch of unrelated inexact matches. I'm missing something obvious. Obviously :-(

Upvotes: 1

Views: 341

Answers (1)

Jesse Wilson
Jesse Wilson

Reputation: 40623

Set this request header:

Accept-Encoding: gzip

Or replace gzip with identity for no compression. In either case OkHttp won't interfere if you provide your own Accept-Encoding header.

Upvotes: 1

Related Questions