Request/Response Headers - Fix incorrect handling of readonly

- Rename ReadOnlyNameValueCollection to HeaderNameValueCollection
- Set ReadOnly after the collection has been populated.

Resolves #2946
This commit is contained in:
amaitland
2019-10-29 19:36:01 +10:00
parent fdc02076ce
commit a8d5b85ed3
4 changed files with 19 additions and 23 deletions
+6 -10
View File
@@ -111,16 +111,7 @@ namespace CefSharp
CefRequest::HeaderMap hm;
_wrappedRequest->GetHeaderMap(hm);
NameValueCollection^ headers;
if (_wrappedRequest->IsReadOnly())
{
headers = gcnew ReadOnlyNameValueCollection();
}
else
{
headers = gcnew NameValueCollection();
}
auto headers = gcnew HeaderNameValueCollection();
for (CefRequest::HeaderMap::iterator it = hm.begin(); it != hm.end(); ++it)
{
@@ -129,6 +120,11 @@ namespace CefSharp
headers->Add(name, value);
}
if (_wrappedRequest->IsReadOnly())
{
headers->SetReadOnly();
}
return headers;
}
+6 -10
View File
@@ -143,16 +143,7 @@ namespace CefSharp
CefRequest::HeaderMap hm;
_response->GetHeaderMap(hm);
NameValueCollection^ headers;
if (_response->IsReadOnly())
{
headers = gcnew ReadOnlyNameValueCollection();
}
else
{
headers = gcnew NameValueCollection();
}
auto headers = gcnew HeaderNameValueCollection();
for (CefRequest::HeaderMap::iterator it = hm.begin(); it != hm.end(); ++it)
{
@@ -161,6 +152,11 @@ namespace CefSharp
headers->Add(name, value);
}
if (_response->IsReadOnly())
{
headers->SetReadOnly();
}
return headers;
}
void set(NameValueCollection^ headers)
+1 -1
View File
@@ -104,7 +104,7 @@
<Compile Include="Enums\SchemeOptions.cs" />
<Compile Include="Internals\CommandLineArgDictionary.cs" />
<Compile Include="Internals\ParentProcessMonitor.cs" />
<Compile Include="Internals\ReadOnlyNameValueCollection.cs" />
<Compile Include="Internals\HeaderNameValueCollection.cs" />
<Compile Include="Internals\TaskScheduler\LimitedConcurrencyLevelTaskScheduler.cs" />
<Compile Include="IUrlRequest.cs" />
<Compile Include="IUrlRequestClient.cs" />
@@ -6,9 +6,13 @@ using System.Collections.Specialized;
namespace CefSharp.Internals
{
public class ReadOnlyNameValueCollection : NameValueCollection
/// <summary>
/// A <see cref="NameValueCollection"/> implementation
/// that can optionally be set to ReadOnly (used to represent the CefHeaderMap)
/// </summary>
public class HeaderNameValueCollection : NameValueCollection
{
public ReadOnlyNameValueCollection()
public void SetReadOnly()
{
IsReadOnly = true;
}