Skip to content

Commit 6727073

Browse files
authored
Fix bug with case-sensitive header comparisions (#5940)
* Fix bug with case-sensitive header comparisons * OrdinalIgnoreCase vs InvariantCultureIgnoreCase
1 parent d696dcd commit 6727073

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/Elasticsearch.Net/Connection/HttpWebRequestConnection.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,13 @@ public virtual TResponse Request<TResponse>(RequestData requestData)
7272
HandleResponse(httpWebResponse, out statusCode, out responseStream, out mimeType);
7373

7474
//response.Headers.HasKeys() can return false even if response.Headers.AllKeys has values.
75-
if (httpWebResponse.SupportsHeaders && httpWebResponse.Headers.Count > 0 && httpWebResponse.Headers.AllKeys.Contains("Warning"))
75+
if (httpWebResponse.SupportsHeaders && httpWebResponse.Headers.Count > 0
76+
&& httpWebResponse.Headers.AllKeys.Contains("Warning", StringComparer.OrdinalIgnoreCase))
7677
warnings = httpWebResponse.Headers.GetValues("Warning");
7778

7879
//response.Headers.HasKeys() can return false even if response.Headers.AllKeys has values.
7980
if (httpWebResponse.SupportsHeaders && httpWebResponse.Headers.Count > 0
80-
&& httpWebResponse.Headers.AllKeys.Contains("X-elastic-product"))
81+
&& httpWebResponse.Headers.AllKeys.Contains("X-elastic-product", StringComparer.OrdinalIgnoreCase))
8182
productNames = httpWebResponse.Headers.GetValues("X-elastic-product");
8283
}
8384
catch (WebException e)
@@ -152,12 +153,13 @@ CancellationToken cancellationToken
152153

153154
var httpWebResponse = (HttpWebResponse)await apmGetResponseTask.ConfigureAwait(false);
154155
HandleResponse(httpWebResponse, out statusCode, out responseStream, out mimeType);
155-
if (httpWebResponse.SupportsHeaders && httpWebResponse.Headers.HasKeys() && httpWebResponse.Headers.AllKeys.Contains("Warning"))
156+
if (httpWebResponse.SupportsHeaders && httpWebResponse.Headers.HasKeys()
157+
&& httpWebResponse.Headers.AllKeys.Contains("Warning", StringComparer.OrdinalIgnoreCase))
156158
warnings = httpWebResponse.Headers.GetValues("Warning");
157159

158160
//response.Headers.HasKeys() can return false even if response.Headers.AllKeys has values.
159161
if (httpWebResponse.SupportsHeaders && httpWebResponse.Headers.Count > 0
160-
&& httpWebResponse.Headers.AllKeys.Contains("X-elastic-product"))
162+
&& httpWebResponse.Headers.AllKeys.Contains("X-elastic-product", StringComparer.OrdinalIgnoreCase))
161163
productNames = httpWebResponse.Headers.GetValues("X-elastic-product");
162164
}
163165
}

0 commit comments

Comments
 (0)