user6817124
user6817124

Reputation: 31

Camel HTTP4 removes content-encoding header on bridgeEndpoint=true

With a route like this

<route id="proxy">
  <from uri="jetty:http://0.0.0.0:9092/Domain?matchOnUriPrefix=true"/>
  <to uri="http4://localhost:8080/Domain?bridgeEndpoint=true&amp;throwExceptionOnFailure=false"/>
</route>

The response from the proxy is not GZIP encoded if the response from local host is.

Response from localhost:8080

HTTP/1.1 202 Accepted
Server: Apache-Coyote/1.1
Content-Encoding: gzip
Date: Sat, 10 Sep 2016 15:39:31 GMT
Vary: Accept-Encoding
Content-Type: multipart/mixed
Transfer-Encoding: chunked

Response from localhost:9092

HTTP/1.1 202 Accepted
Content-Type: multipart/mixed
Server: Apache-Coyote/1.1
Vary: Accept-Encoding
Transfer-Encoding: chunked

The HTTP4 component seems to uncompress the GZIP stream and remove the Content-Encoding header even though the bridgeEndpoint is set to true?

When I do the same proxy with in the to uri

<to uri="http://localhost:8080/ReferenceDomain.svc?bridgeEndpoint=true&amp;throwExceptionOnFailure=false"/>

or

<to uri="jetty:http://localhost:8080/ReferenceDomain.svc?bridgeEndpoint=true&amp;throwExceptionOnFailure=false"/>

it works as expected.

What am I missing/doing wrong?

(I am using Camel 2.15.1)

Upvotes: 3

Views: 2458

Answers (1)

Pavel F
Pavel F

Reputation: 53

It might be too late for an answer, but i recently stumbled upon the same issue, e.g. Content-Encoding header is removed when proxying requests through Camel. Initially I thought something wrong with Camel HTTP Component, but it is apparently Apache HTTP Client.

E.g. if you leave default configuration for Apache HTTP Client builder in Camel, it would come back with interceptor which automatically decodes gzip'ed content and clears Content-Encoding header from response, thus Camel doesn't even have chance to read the header. Check contentCompressionDisabled property of the HttpClientBuilder.

So, my solution was to override default HttpClientBuilder to disable content compression, e.g.

public class CustomHttp4Component extends HttpComponent {
  @Override
  protected HttpClientBuilder createHttpClientBuilder(final String uri, final Map<String, Object> parameters,
                                                    final Map<String, Object> httpClientOptions) throws Exception {
    HttpClientBuilder builder = super.createHttpClientBuilder(uri, parameters, httpClientOptions);
    // If not set, http client will decompress the entity and remove content-encoding headers from response.
    // There is logic in Camel to decompress if header is set hence we leave decompression logic to Camel and disable decomp in Apache HTTP client.
    builder.disableContentCompression();
    return builder;
}

Upvotes: 1

Related Questions