Skip to content

Commit c67c213

Browse files
committed
HttpClientConnection (alternative for the builtin) had a NRE causing it to misbehave
1 parent ed92427 commit c67c213

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Connections/Elasticsearch.Net.Connection.HttpClient/HttpClientConnection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,6 @@ public async Task<ElasticsearchResponse<Stream>> DoRequest(HttpMethod method, Ur
126126
else if (!string.IsNullOrWhiteSpace(DefaultContentType))
127127
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(DefaultContentType));
128128

129-
if (!string.IsNullOrWhiteSpace(DefaultContentType))
130-
request.Content.Headers.ContentType = new MediaTypeHeaderValue(DefaultContentType);
131129

132130
if (!string.IsNullOrEmpty(uri.UserInfo))
133131
{
@@ -137,6 +135,8 @@ public async Task<ElasticsearchResponse<Stream>> DoRequest(HttpMethod method, Ur
137135
if (method != HttpMethod.Get && method != HttpMethod.Head && data != null && data.Length > 0)
138136
{
139137
request.Content = new ByteArrayContent(data);
138+
if (!string.IsNullOrWhiteSpace(DefaultContentType) && request.Content != null && request.Content.Headers != null)
139+
request.Content.Headers.ContentType = new MediaTypeHeaderValue(DefaultContentType);
140140
}
141141

142142
var response = await Client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);

0 commit comments

Comments
 (0)