@@ -38,9 +38,6 @@ public HttpClientConnection(IConnectionConfigurationValues settings, HttpClientH
3838
3939 var innerHandler = handler ?? new WebRequestHandler ( ) ;
4040
41- if ( settings . EnableCompressedResponses )
42- innerHandler . AutomaticDecompression = DecompressionMethods . GZip | DecompressionMethods . Deflate ;
43-
4441 if ( innerHandler . SupportsProxy && ! string . IsNullOrWhiteSpace ( _settings . ProxyAddress ) )
4542 {
4643 innerHandler . Proxy = new WebProxy ( _settings . ProxyAddress )
@@ -56,6 +53,12 @@ public HttpClientConnection(IConnectionConfigurationValues settings, HttpClientH
5653 {
5754 Timeout = TimeSpan . FromMilliseconds ( _settings . Timeout )
5855 } ;
56+ if ( settings . EnableCompressedResponses && innerHandler . SupportsAutomaticDecompression )
57+ {
58+ innerHandler . AutomaticDecompression = DecompressionMethods . GZip | DecompressionMethods . Deflate ;
59+ Client . DefaultRequestHeaders . AcceptEncoding . Add ( new StringWithQualityHeaderValue ( "gzip" ) ) ;
60+ Client . DefaultRequestHeaders . AcceptEncoding . Add ( new StringWithQualityHeaderValue ( "deflate" ) ) ;
61+ }
5962
6063 }
6164
@@ -126,7 +129,6 @@ public async Task<ElasticsearchResponse<Stream>> DoRequest(HttpMethod method, Ur
126129 else if ( ! string . IsNullOrWhiteSpace ( DefaultContentType ) )
127130 request . Headers . Accept . Add ( new MediaTypeWithQualityHeaderValue ( DefaultContentType ) ) ;
128131
129-
130132 if ( ! string . IsNullOrEmpty ( uri . UserInfo ) )
131133 {
132134 request . Headers . Authorization = new AuthenticationHeaderValue ( "Basic" , Convert . ToBase64String ( Encoding . UTF8 . GetBytes ( uri . UserInfo ) ) ) ;
@@ -141,7 +143,7 @@ public async Task<ElasticsearchResponse<Stream>> DoRequest(HttpMethod method, Ur
141143
142144 var response = await Client . SendAsync ( request , HttpCompletionOption . ResponseHeadersRead ) ;
143145
144- if ( method == HttpMethod . Head || response . Content == null || ! response . Content . Headers . ContentLength . HasValue || response . Content . Headers . ContentLength . Value <= 0 )
146+ if ( method == HttpMethod . Head || response . Content == null )
145147 {
146148 return ElasticsearchResponse < Stream > . Create ( _settings , ( int ) response . StatusCode , method . ToString ( ) . ToLowerInvariant ( ) , uri . ToString ( ) , data ) ;
147149 }
0 commit comments