Right way to remove Gzip encoding in the client

Trying to debug a request with Gzip-encoding turned on is kind of painful, how can I disable this header in the client?

Which Client are you using?

2019-09-23 15:54:53.793 DEBUG 18652 — [ Test worker] org.apache.http.wire : http-outgoing-0 >> “User-Agent: HAPI-FHIR/3.8.0 (FHIR Client; FHIR 4.0.0/R4; apache)[\r][\n]”

I should probably say, that my goal is just to be able to read the actual body content, maybe there’s some way to make apache http client decode it before logging the response.

I’ve tried this, but it didn’t work, I thought this was coming from a default, but either it’s being overridden somewhere, or it’s not just a default

    @Bean
    open fun httpClient(): CloseableHttpClient {
        //FIXME potential resoource leak
        val connectionManager = PoolingHttpClientConnectionManager(
            5000,
            TimeUnit.MILLISECONDS
        )

        val defaultRequestConfig = RequestConfig.custom()
            .build()

        val builder = HttpClients.custom().setConnectionManager(connectionManager)
            .setDefaultRequestConfig(defaultRequestConfig).disableCookieManagement()

        return builder.disableContentCompression() .build()
    }


    @Bean
    @ConditionalOnProperty(name = ["site.fhir.endpoint"])
    open fun client2( client: CloseableHttpClient ): IGenericClient {
        val rcf = FhirContext(fhir?.version).restfulClientFactory
        rcf.setHttpClient(client)
        return rcf.newGenericClient(fhir?.endpoint)
    }

this works, I verified disableContentCompression() was working, but the header was still added, I’m not sure where I had to use the interceptor to actually remove it, this feels wrong, I would like to know where it’s being added, it feels like HAPI must be adding it again somewhere, if so I’d like to see a feature to disable it.

    val builder = HttpClients.custom()
        .setConnectionManager(connectionManager)
        .disableContentCompression()
        .disableCookieManagement()
        .addInterceptorLast(HttpRequestInterceptor { request, _ ->
            request.removeHeaders("Accept-Encoding")
        })

If your aim here is just to see the payload over the wire, consider registering the LoggingInterceptor against the client, e.g.

client.registerInterceptor(new LoggingInterceptor(true));

This happens at the application layer so it logs the uncompressed contents.