@@ -36,14 +36,14 @@ public class HttpConnection : IConnection
3636 protected readonly ConcurrentDictionary < int , HttpClient > Clients = new ConcurrentDictionary < int , HttpClient > ( ) ;
3737
3838 private static readonly string CanNotUseStreamResponsesWithCurlHandler =
39- "Using Stream as TReturn does not work as expected on .NET core linux, because we can no longer guarantee this works it will be removed from the client in our 6.0 release"
39+ "Using Stream as TReturn does not work as expected on .NET core linux. " +
40+ "Because we can no longer guarantee this works it will be removed from the client in our 6.0 release"
4041 ;
4142
4243 private HttpClient GetClient ( RequestData requestData )
4344 {
4445 var key = GetClientKey ( requestData ) ;
45- HttpClient client ;
46- if ( this . Clients . TryGetValue ( key , out client ) ) return client ;
46+ if ( this . Clients . TryGetValue ( key , out var client ) ) return client ;
4747 lock ( _lock )
4848 {
4949 client = this . Clients . GetOrAdd ( key , h =>
@@ -64,8 +64,6 @@ private HttpClient GetClient(RequestData requestData)
6464
6565 public virtual ElasticsearchResponse < TReturn > Request < TReturn > ( RequestData requestData ) where TReturn : class
6666 {
67- //TODO remove Stream response support in 6.0, closing the stream is sufficient on desktop/mono
68- //but not on .NET core on linux HttpClient which proxies to curl.
6967 if ( typeof ( TReturn ) == typeof ( Stream ) && ConnectionConfiguration . IsCurlHandler )
7068 throw new Exception ( CanNotUseStreamResponsesWithCurlHandler ) ;
7169
@@ -78,10 +76,11 @@ public virtual ElasticsearchResponse<TReturn> Request<TReturn>(RequestData reque
7876 responseMessage = client . SendAsync ( requestMessage ) . GetAwaiter ( ) . GetResult ( ) ;
7977 requestData . MadeItToResponse = true ;
8078 builder . StatusCode = ( int ) responseMessage . StatusCode ;
81- IEnumerable < string > warnings ;
82- if ( responseMessage . Headers . TryGetValues ( "Warning" , out warnings ) )
79+ if ( responseMessage . Headers . TryGetValues ( "Warning" , out var warnings ) )
8380 builder . DeprecationWarnings = warnings ;
8481
82+ builder . ResponseMimeType = responseMessage . Content . Headers . ContentType ? . MediaType ;
83+
8584 if ( responseMessage . Content != null )
8685 builder . Stream = responseMessage . Content . ReadAsStreamAsync ( ) . GetAwaiter ( ) . GetResult ( ) ;
8786 // https://github.com/elastic/elasticsearch-net/issues/2311
@@ -107,8 +106,6 @@ public virtual ElasticsearchResponse<TReturn> Request<TReturn>(RequestData reque
107106 public virtual async Task < ElasticsearchResponse < TReturn > > RequestAsync < TReturn > ( RequestData requestData ,
108107 CancellationToken cancellationToken ) where TReturn : class
109108 {
110- //TODO remove Stream response support in 6.0, closing the stream is sufficient on desktop/mono
111- //but not on .NET core on linux HttpClient which proxies to curl.
112109 if ( typeof ( TReturn ) == typeof ( Stream ) && ConnectionConfiguration . IsCurlHandler )
113110 throw new Exception ( CanNotUseStreamResponsesWithCurlHandler ) ;
114111
@@ -121,10 +118,11 @@ public virtual async Task<ElasticsearchResponse<TReturn>> RequestAsync<TReturn>(
121118 responseMessage = await client . SendAsync ( requestMessage , cancellationToken ) . ConfigureAwait ( false ) ;
122119 requestData . MadeItToResponse = true ;
123120 builder . StatusCode = ( int ) responseMessage . StatusCode ;
124- IEnumerable < string > warnings ;
125- if ( responseMessage . Headers . TryGetValues ( "Warning" , out warnings ) )
121+ if ( responseMessage . Headers . TryGetValues ( "Warning" , out var warnings ) )
126122 builder . DeprecationWarnings = warnings ;
127123
124+ builder . ResponseMimeType = responseMessage . Content . Headers . ContentType ? . MediaType ;
125+
128126 if ( responseMessage . Content != null )
129127 builder . Stream = await responseMessage . Content . ReadAsStreamAsync ( ) . ConfigureAwait ( false ) ;
130128 // https://github.com/elastic/elasticsearch-net/issues/2311
@@ -250,7 +248,7 @@ protected virtual HttpRequestMessage CreateRequestMessage(RequestData requestDat
250248 else
251249 {
252250 // Set content in order to set a Content-Type header.
253- // Content gets diposed so can't be shared instance
251+ // Content gets disposed so can't be shared instance
254252 requestMessage . Content = new ByteArrayContent ( new byte [ 0 ] ) ;
255253 }
256254
0 commit comments