Return-Path: X-Original-To: apmail-hc-httpclient-users-archive@www.apache.org Delivered-To: apmail-hc-httpclient-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1FEA719D20 for ; Wed, 20 Apr 2016 15:03:37 +0000 (UTC) Received: (qmail 13517 invoked by uid 500); 20 Apr 2016 15:03:36 -0000 Delivered-To: apmail-hc-httpclient-users-archive@hc.apache.org Received: (qmail 13476 invoked by uid 500); 20 Apr 2016 15:03:36 -0000 Mailing-List: contact httpclient-users-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpClient User Discussion" Delivered-To: mailing list httpclient-users@hc.apache.org Received: (qmail 13465 invoked by uid 99); 20 Apr 2016 15:03:36 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Apr 2016 15:03:36 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 414ABC0845 for ; Wed, 20 Apr 2016 15:03:35 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -3.003 X-Spam-Level: X-Spam-Status: No, score=-3.003 tagged_above=-999 required=6.31 tests=[HTML_MESSAGE=2, RCVD_IN_DNSWL_HI=-5, RP_MATCHES_RCVD=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001] autolearn=disabled Received: from mx2-lw-us.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id sJWGb969UzIw for ; Wed, 20 Apr 2016 15:03:33 +0000 (UTC) Received: from mx1a.expedia.com (mx1a.expedia.com [216.251.112.221]) by mx2-lw-us.apache.org (ASF Mail Server at mx2-lw-us.apache.org) with ESMTPS id 63D305F1D5 for ; Wed, 20 Apr 2016 15:03:33 +0000 (UTC) X-SRBS: None X-HAT: Sender Group RELAYLIST, Policy $RELAYED applied. X-MailPolicy: Default Outgoing Mail Policy Received: from unknown (HELO CHCXEXCHMBX001.SEA.CORP.EXPECN.com) ([10.184.69.18]) by mx1a.sea.corp.expecn.com with ESMTP; 20 Apr 2016 08:03:25 -0700 Received: from CHCXEXCHMBX001.SEA.CORP.EXPECN.com (10.184.69.18) by CHCXEXCHMBX001.SEA.CORP.EXPECN.com (10.184.69.18) with Microsoft SMTP Server (TLS) id 15.0.1104.5; Wed, 20 Apr 2016 08:03:24 -0700 Received: from CHCXEXCHMBX001.SEA.CORP.EXPECN.com ([fe80::a5b1:e088:3612:fb14]) by CHCXEXCHMBX001.SEA.CORP.EXPECN.com ([fe80::a5b1:e088:3612:fb14%15]) with mapi id 15.00.1104.000; Wed, 20 Apr 2016 08:03:24 -0700 From: Sven Zethelius To: "httpclient-users@hc.apache.org" Subject: httpasyncclient BasicAsyncRequestProducer prevents HttpRequestInterceptor from replacing HttpEntity of the request Thread-Topic: httpasyncclient BasicAsyncRequestProducer prevents HttpRequestInterceptor from replacing HttpEntity of the request Thread-Index: AQHRmxXJQSUJRmklGkyfzYMEzsXbLQ== Date: Wed, 20 Apr 2016 15:03:24 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: user-agent: Microsoft-MacOutlook/14.4.7.141117 x-ms-exchange-messagesentrepresentingtype: 1 x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.184.67.5] Content-Type: multipart/alternative; boundary="_000_D33CE8483B59Fsvenzexpediacom_" MIME-Version: 1.0 --_000_D33CE8483B59Fsvenzexpediacom_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I am trying to use a HttpRequestInterceptor to adapt a request sent to a or= g.apache.http.impl.nio.client.CloseableHttpAsyncClient. I want to do reque= st body compression (e.g. Content-Encoding: gzip for HttpRequest, not Accep= t-Encoding) following the example here: https://hc.apache.org/httpcomponent= s-client-4.2.x/httpclient/examples/org/apache/http/examples/client/ClientGZ= ipContentCompression.java . The example is for response compression, but i= t looked like I could do the same thing to do request compression, and I ne= ed to handle response compression too. After much debugging I realized the HttpRequestInterceptor would allow me t= o change the headers, but not the HttpEntity that was sent. The entity sen= t is always the original one passed into the AsyncHttpClient. On the serve= r, I see the "Content-Type: gzip" and a "Content-Length" header for the gzi= pped length (Content-Length was set by the internal interceptors), but the = bytes sent are the original values from the NByteArrayEntity, which leads t= o exceptions since Content-Length doesn't match actual length after GZIP. I tracked it down to the constructor for org.apache.http.nio.protocol.Basic= AsyncRequestProducer. The BasicAsyncRequestProducer is created before the = interceptors run. In the producer constructor, the entity from the request= is stored as the producer. This occurs before the HttpRequestInterceptor = has a chance to manipulate the entity. My idea for a patch would be to delay load the producer field until after t= he interceptors have run. Looking at the class, that would have to be in p= roduceContent, before it checks for producer=3D=3Dnull. Since the request i= s also a member, this would allow the producer to be set based on what's in= the request when we actually produce the output, rather than what was in i= t when the whole processing chain started. Is patching the BasicAsyncRequestProducer the only way to do this or is the= re a simpler way that I am missing? --_000_D33CE8483B59Fsvenzexpediacom_--