Fixed RequestHeader to allow working with KeyValuePair. #12114 (#12157)

This commit is contained in:
Carlos J. Aliaga 2019-07-14 15:11:50 +02:00 committed by Chris Ross
parent c5cf99f6a2
commit 7d050e803f
2 changed files with 23 additions and 4 deletions

View File

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Sockets;
using System.Text;
@ -57,7 +58,26 @@ namespace Microsoft.AspNetCore.Server.HttpSys
await SendRequestAsync(address, "Custom-Header", customValues);
}
}
[ConditionalFact]
public async Task RequestHeaders_ServerAddsCustomHeaders_Success()
{
string address;
using (Utilities.CreateHttpServer(out address, httpContext =>
{
var requestHeaders = httpContext.Request.Headers;
var header = KeyValuePair.Create("Custom-Header", new StringValues("custom"));
requestHeaders.Add(header);
Assert.True(requestHeaders.Contains(header));
return Task.FromResult(0);
}))
{
string response = await SendRequestAsync(address);
Assert.Equal(string.Empty, response);
}
}
private async Task<string> SendRequestAsync(string uri)
{
using (HttpClient client = new HttpClient())

View File

@ -110,7 +110,7 @@ namespace Microsoft.AspNetCore.HttpSys.Internal
void ICollection<KeyValuePair<string, StringValues>>.Add(KeyValuePair<string, StringValues> item)
{
((IDictionary<string, object>)this).Add(item.Key, item.Value);
((IDictionary<string, StringValues>)this).Add(item.Key,item.Value);
}
void ICollection<KeyValuePair<string, StringValues>>.Clear()
@ -124,8 +124,7 @@ namespace Microsoft.AspNetCore.HttpSys.Internal
bool ICollection<KeyValuePair<string, StringValues>>.Contains(KeyValuePair<string, StringValues> item)
{
object value;
return ((IDictionary<string, object>)this).TryGetValue(item.Key, out value) && Object.Equals(value, item.Value);
return ((IDictionary<string, StringValues>)this).TryGetValue(item.Key, out var value) && Equals(value, item.Value);
}
void ICollection<KeyValuePair<string, StringValues>>.CopyTo(KeyValuePair<string, StringValues>[] array, int arrayIndex)