33using System . Net ;
44using System . Net . Http ;
55using System . Net . Http . Headers ;
6+ using System . Text ;
67using System . Threading . Tasks ;
78using Elasticsearch . Net . Connection . Configuration ;
89
@@ -37,10 +38,14 @@ public HttpClientConnection(IConnectionConfigurationValues settings, HttpClientH
3738
3839 var innerHandler = handler ?? new WebRequestHandler ( ) ;
3940
41+ if ( settings . EnableCompressedResponses )
42+ innerHandler . AutomaticDecompression = DecompressionMethods . GZip | DecompressionMethods . Deflate ;
43+
4044 if ( innerHandler . SupportsProxy && ! string . IsNullOrWhiteSpace ( _settings . ProxyAddress ) )
4145 {
4246 innerHandler . Proxy = new WebProxy ( _settings . ProxyAddress )
4347 {
48+
4449 Credentials = new NetworkCredential ( _settings . ProxyUsername , _settings . ProxyPassword ) ,
4550 } ;
4651
@@ -51,6 +56,7 @@ public HttpClientConnection(IConnectionConfigurationValues settings, HttpClientH
5156 {
5257 Timeout = TimeSpan . FromMilliseconds ( _settings . Timeout )
5358 } ;
59+
5460 }
5561
5662 /// <summary>
@@ -115,24 +121,22 @@ public async Task<ElasticsearchResponse<Stream>> DoRequest(HttpMethod method, Ur
115121 try
116122 {
117123 var request = new HttpRequestMessage ( method , uri ) ;
124+ if ( requestSpecificConfig != null && ! string . IsNullOrWhiteSpace ( requestSpecificConfig . ContentType ) )
125+ request . Headers . Accept . Add ( new MediaTypeWithQualityHeaderValue ( requestSpecificConfig . ContentType ) ) ;
126+ else if ( ! string . IsNullOrWhiteSpace ( DefaultContentType ) )
127+ request . Headers . Accept . Add ( new MediaTypeWithQualityHeaderValue ( DefaultContentType ) ) ;
128+
129+ if ( ! string . IsNullOrWhiteSpace ( DefaultContentType ) )
130+ request . Content . Headers . ContentType = new MediaTypeHeaderValue ( DefaultContentType ) ;
131+
132+ if ( ! string . IsNullOrEmpty ( uri . UserInfo ) )
133+ {
134+ request . Headers . Authorization = new AuthenticationHeaderValue ( "Basic" , Convert . ToBase64String ( Encoding . UTF8 . GetBytes ( uri . UserInfo ) ) ) ;
135+ }
118136
119137 if ( method != HttpMethod . Get && method != HttpMethod . Head && data != null && data . Length > 0 )
120138 {
121139 request . Content = new ByteArrayContent ( data ) ;
122-
123- if ( requestSpecificConfig != null && ! string . IsNullOrWhiteSpace ( requestSpecificConfig . ContentType ) )
124- {
125- request . Headers . Accept . Add ( new MediaTypeWithQualityHeaderValue ( requestSpecificConfig . ContentType ) ) ;
126- }
127- else if ( ! string . IsNullOrWhiteSpace ( DefaultContentType ) )
128- {
129- request . Headers . Accept . Add ( new MediaTypeWithQualityHeaderValue ( DefaultContentType ) ) ;
130- }
131-
132- if ( ! string . IsNullOrWhiteSpace ( DefaultContentType ) )
133- {
134- request . Content . Headers . ContentType = new MediaTypeHeaderValue ( DefaultContentType ) ;
135- }
136140 }
137141
138142 var response = await Client . SendAsync ( request , HttpCompletionOption . ResponseHeadersRead ) ;
0 commit comments