@@ -38,9 +38,6 @@ public HttpClientConnection(IConnectionConfigurationValues settings, HttpClientH
38
38
39
39
var innerHandler = handler ?? new WebRequestHandler ( ) ;
40
40
41
- if ( settings . EnableCompressedResponses )
42
- innerHandler . AutomaticDecompression = DecompressionMethods . GZip | DecompressionMethods . Deflate ;
43
-
44
41
if ( innerHandler . SupportsProxy && ! string . IsNullOrWhiteSpace ( _settings . ProxyAddress ) )
45
42
{
46
43
innerHandler . Proxy = new WebProxy ( _settings . ProxyAddress )
@@ -56,6 +53,12 @@ public HttpClientConnection(IConnectionConfigurationValues settings, HttpClientH
56
53
{
57
54
Timeout = TimeSpan . FromMilliseconds ( _settings . Timeout )
58
55
} ;
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
+ }
59
62
60
63
}
61
64
@@ -126,7 +129,6 @@ public async Task<ElasticsearchResponse<Stream>> DoRequest(HttpMethod method, Ur
126
129
else if ( ! string . IsNullOrWhiteSpace ( DefaultContentType ) )
127
130
request . Headers . Accept . Add ( new MediaTypeWithQualityHeaderValue ( DefaultContentType ) ) ;
128
131
129
-
130
132
if ( ! string . IsNullOrEmpty ( uri . UserInfo ) )
131
133
{
132
134
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
141
143
142
144
var response = await Client . SendAsync ( request , HttpCompletionOption . ResponseHeadersRead ) ;
143
145
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 )
145
147
{
146
148
return ElasticsearchResponse < Stream > . Create ( _settings , ( int ) response . StatusCode , method . ToString ( ) . ToLowerInvariant ( ) , uri . ToString ( ) , data ) ;
147
149
}
0 commit comments