Switch to using Dictionary initializer, and add check for SupportsHeaders

This commit is contained in:
Jacob Alber 2017-10-06 13:20:08 -04:00
Родитель 6bf6201cad
Коммит 139a42521a
1 изменённых файлов: 13 добавлений и 8 удалений

Просмотреть файл

@ -117,17 +117,22 @@ namespace Microsoft.DecisionService.Crawl
catch (WebException we)
{
HttpWebResponse httpResponse = we.Response as HttpWebResponse;
if (we.Status == WebExceptionStatus.ServerProtocolViolation)
if (we.Status == WebExceptionStatus.ServerProtocolViolation && we.Response != null)
{
// Get a little more telemetry about what is going on here.
IDictionary<string, string> traceData = new Dictionary<string, string>();
traceData["Response.SupportsHeaders"] = we.Response.SupportsHeaders.ToString();
for (int i = 0; i < we.Response.Headers.Count; i++)
IDictionary<string, string> traceData = new Dictionary<string, string>()
{
string headerName = we.Response.Headers.GetKey(i);
string headerValue = we.Response.Headers.Get(i);
traceData[$"Response.Headers.{headerName}"] = headerValue;
{ "Response.SupportsHeaders", we.Response.SupportsHeaders.ToString() }
};
if (we.Response.SupportsHeaders)
{
for (int i = 0; i < we.Response.Headers.Count; i++)
{
string headerName = we.Response.Headers.GetKey(i);
string headerValue = we.Response.Headers.Get(i);
traceData[$"Response.Headers.{headerName}"] = headerValue;
}
}
if (httpResponse != null)