Skip to content

Commit 7d050e8

Browse files
cjaliagaTratcher
authored andcommitted
Fixed RequestHeader to allow working with KeyValuePair. #12114 (#12157)
1 parent c5cf99f commit 7d050e8

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/Servers/HttpSys/test/FunctionalTests/RequestHeaderTests.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5+
using System.Collections.Generic;
56
using System.Net.Http;
67
using System.Net.Sockets;
78
using System.Text;
@@ -57,7 +58,26 @@ public async Task RequestHeaders_ClientSendsCustomHeaders_Success()
5758
await SendRequestAsync(address, "Custom-Header", customValues);
5859
}
5960
}
60-
61+
62+
[ConditionalFact]
63+
public async Task RequestHeaders_ServerAddsCustomHeaders_Success()
64+
{
65+
string address;
66+
using (Utilities.CreateHttpServer(out address, httpContext =>
67+
{
68+
var requestHeaders = httpContext.Request.Headers;
69+
var header = KeyValuePair.Create("Custom-Header", new StringValues("custom"));
70+
requestHeaders.Add(header);
71+
72+
Assert.True(requestHeaders.Contains(header));
73+
return Task.FromResult(0);
74+
}))
75+
{
76+
string response = await SendRequestAsync(address);
77+
Assert.Equal(string.Empty, response);
78+
}
79+
}
80+
6181
private async Task<string> SendRequestAsync(string uri)
6282
{
6383
using (HttpClient client = new HttpClient())

src/Shared/HttpSys/RequestProcessing/RequestHeaders.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public bool TryGetValue(string key, out StringValues value)
110110

111111
void ICollection<KeyValuePair<string, StringValues>>.Add(KeyValuePair<string, StringValues> item)
112112
{
113-
((IDictionary<string, object>)this).Add(item.Key, item.Value);
113+
((IDictionary<string, StringValues>)this).Add(item.Key,item.Value);
114114
}
115115

116116
void ICollection<KeyValuePair<string, StringValues>>.Clear()
@@ -124,8 +124,7 @@ void ICollection<KeyValuePair<string, StringValues>>.Clear()
124124

125125
bool ICollection<KeyValuePair<string, StringValues>>.Contains(KeyValuePair<string, StringValues> item)
126126
{
127-
object value;
128-
return ((IDictionary<string, object>)this).TryGetValue(item.Key, out value) && Object.Equals(value, item.Value);
127+
return ((IDictionary<string, StringValues>)this).TryGetValue(item.Key, out var value) && Equals(value, item.Value);
129128
}
130129

131130
void ICollection<KeyValuePair<string, StringValues>>.CopyTo(KeyValuePair<string, StringValues>[] array, int arrayIndex)

0 commit comments

Comments
 (0)