Пример #1
0
        private Response Decompress(Response response)
        {
            _logger?.LogDebug("Decompress response");
            var source = response.Headers("Content-Encoding").Contains("gzip")
                ? (ISource) new GzipSource(response.Body().Source())
                : (ISource) new InflaterSource(response.Body().Source(), new Inflater());
            var bodyString      = OkIO.Buffer(source).ReadUtf8();
            var responseBody    = ResponseBody.Create(bodyString, response.Body().ContentType());
            var strippedHeaders = response.Headers().NewBuilder()
                                  .RemoveAll("Content-Encoding")
                                  .RemoveAll("Content-Length")
                                  .Build();

            return(response.NewBuilder()
                   .Headers(strippedHeaders)
                   .Body(responseBody)
                   .Message(response.Message())
                   .Build());
        }