Imported Upstream version 5.8.0.22

Former-commit-id: df344e34b07851d296efb3e6604c8db42b6f7aa3
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-10-19 20:04:20 +00:00
parent 5f4a27cc8a
commit 7d05485754
5020 changed files with 114082 additions and 186061 deletions

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8" ?>
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
<Library Name="*System.Net.Primitives*">
<Assembly Name="System.Net.Primitives">
<!-- VSO 449560 The following types are used by HttpListener. -->
<Type Name="System.Net.Cookie">
<!-- Used by CookieParser -->
<Method Name="InternalSetName" Dynamic="Required" />
<Field Name="IsQuotedDomain" Dynamic="Required" />
<Field Name="IsQuotedVersion" Dynamic="Required" />
<!-- Used by CookieExtensions -->
<Method Name="ToServerString" Dynamic="Required" />
<Method Name="Clone" Dynamic="Required" />
<Property Name="Variant" Dynamic="Required" />
</Type>
<Type Name="System.Net.CookieCollection">
<Method Name="InternalAdd" Dynamic="Required" />
</Type>
</Assembly>
</Library>
</Directives>

View File

@@ -17,6 +17,7 @@
<!-- SYSTEM_NET_PRIMITIVES_DLL is required to allow source-level code sharing for types defined within the
System.Net.Internals namespace. -->
<DefineConstants>$(DefineConstants);SYSTEM_NET_PRIMITIVES_DLL</DefineConstants>
<DefineConstants Condition="'$(TargetGroup)' == 'uap'">$(DefineConstants);uap</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Include="System\Net\AuthenticationSchemes.cs" />
@@ -186,9 +187,13 @@
<Link>Interop\Unix\System.Native\Interop.SocketAddress.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup Condition=" '$(TargetGroup)' == 'uap'">
<EmbeddedResource Include="Resources\$(AssemblyName).rd.xml" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.Win32.Primitives" />
<Reference Include="System.Collections" />
<Reference Include="System.Collections.NonGeneric" />
<Reference Include="System.Diagnostics.Contracts" />
<Reference Include="System.Diagnostics.Debug" />
<Reference Include="System.Diagnostics.Tracing" />

View File

@@ -10,6 +10,7 @@ using System.Text;
namespace System.Net
{
[System.Runtime.CompilerServices.TypeForwardedFrom("System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public enum CookieVariant
{
Unknown,
@@ -28,7 +29,7 @@ namespace System.Net
// (e.g. "Cookie: $Version=1; name=value; $Path=/foo; $Secure")
[Serializable]
#if !MONO
[System.Runtime.CompilerServices.TypeForwardedFrom("System, Version=4.0.0.0, PublicKeyToken=b77a5c561934e089")]
[System.Runtime.CompilerServices.TypeForwardedFrom("System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
#endif
public sealed class Cookie
{
@@ -50,23 +51,50 @@ namespace System.Net
private CookieVariant m_cookieVariant = CookieVariant.Plain; // Do not rename (binary serialization)
private bool m_discard = false; // Do not rename (binary serialization)
private string m_domain = string.Empty; // Do not rename (binary serialization)
private bool m_domainImplicit = true; // Do not rename (binary serialization)
private bool m_domain_implicit = true; // Do not rename (binary serialization)
private DateTime m_expires = DateTime.MinValue; // Do not rename (binary serialization)
private string m_name = string.Empty; // Do not rename (binary serialization)
private string m_path = string.Empty; // Do not rename (binary serialization)
private bool m_pathImplicit = true; // Do not rename (binary serialization)
private bool m_path_implicit = true; // Do not rename (binary serialization)
private string m_port = string.Empty; // Do not rename (binary serialization)
private bool m_portImplicit = true; // Do not rename (binary serialization)
private int[] m_portList = null; // Do not rename (binary serialization)
private bool m_port_implicit = true; // Do not rename (binary serialization)
private int[] m_port_list = null; // Do not rename (binary serialization)
private bool m_secure = false; // Do not rename (binary serialization)
[System.Runtime.Serialization.OptionalField]
private bool m_httpOnly = false; // Do not rename (binary serialization)
private DateTime m_timeStamp = DateTime.Now; // Do not rename (binary serialization)
private string m_value = string.Empty; // Do not rename (binary serialization)
private int m_version = 0; // Do not rename (binary serialization)
private string m_domainKey = string.Empty; // Do not rename (binary serialization)
internal bool IsQuotedVersion = false;
internal bool IsQuotedDomain = false;
/*
TODO: #13607
VSO 449560
Reflecting on internal method won't work on AOT without rd.xml and DisableReflection
block in toolchain.Networking team will be working on exposing methods from S.Net.Primitive
public, this is a temporary workaround till that happens.
*/
#if uap
public
#else
internal
#endif
bool IsQuotedVersion = false;
/*
TODO: #13607
VSO 449560
Reflecting on internal method won't work on AOT without rd.xml and DisableReflection
block in toolchain.Networking team will be working on exposing methods from S.Net.Primitive
public, this is a temporary workaround till that happens.
*/
#if uap
public
#else
internal
#endif
bool IsQuotedDomain = false;
#if DEBUG
static Cookie()
@@ -156,7 +184,7 @@ namespace System.Net
set
{
m_domain = value ?? string.Empty;
m_domainImplicit = false;
m_domain_implicit = false;
m_domainKey = string.Empty; // _domainKey will be set when adding this cookie to a container.
}
}
@@ -165,11 +193,11 @@ namespace System.Net
{
get
{
return m_domainImplicit;
return m_domain_implicit;
}
set
{
m_domainImplicit = value;
m_domain_implicit = value;
}
}
@@ -215,7 +243,19 @@ namespace System.Net
}
}
internal bool InternalSetName(string value)
/*
TODO: #13607
VSO 449560
Reflecting on internal method won't work on AOT without rd.xml and DisableReflection
block in toolchain.Networking team will be working on exposing methods from S.Net.Primitive
public, this is a temporary workaround till that happens.
*/
#if uap
public
#else
internal
#endif
bool InternalSetName(string value)
{
if (String.IsNullOrEmpty(value) || value[0] == '$' || value.IndexOfAny(ReservedToName) != -1)
{
@@ -235,7 +275,7 @@ namespace System.Net
set
{
m_path = value ?? string.Empty;
m_pathImplicit = false;
m_path_implicit = false;
}
}
@@ -247,23 +287,35 @@ namespace System.Net
}
}
internal Cookie Clone()
/*
TODO: #13607
VSO 449560
Reflecting on internal method won't work on AOT without rd.xml and DisableReflection
block in toolchain.Networking team will be working on exposing methods from S.Net.Primitive
public, this is a temporary workaround till that happens.
*/
#if uap
public
#else
internal
#endif
Cookie Clone()
{
Cookie clonedCookie = new Cookie(m_name, m_value);
// Copy over all the properties from the original cookie
if (!m_portImplicit)
if (!m_port_implicit)
{
clonedCookie.Port = m_port;
}
if (!m_pathImplicit)
if (!m_path_implicit)
{
clonedCookie.Path = m_path;
}
clonedCookie.Domain = m_domain;
// If the domain in the original cookie was implicit, we should preserve that property
clonedCookie.DomainImplicit = m_domainImplicit;
clonedCookie.DomainImplicit = m_domain_implicit;
clonedCookie.m_timeStamp = m_timeStamp;
clonedCookie.Comment = m_comment;
clonedCookie.CommentUri = m_commentUri;
@@ -365,13 +417,13 @@ namespace System.Net
// Check/set domain
//
// If domain is implicit => assume a) uri is valid, b) just set domain to uri hostname.
if (setDefault && m_domainImplicit == true)
if (setDefault && m_domain_implicit == true)
{
m_domain = host;
}
else
{
if (!m_domainImplicit)
if (!m_domain_implicit)
{
// Forwarding note: If Uri.Host is of IP address form then the only supported case
// is for IMPLICIT domain property of a cookie.
@@ -472,7 +524,7 @@ namespace System.Net
}
// Check/Set Path
if (setDefault && m_pathImplicit == true)
if (setDefault && m_path_implicit == true)
{
// This code assumes that the URI path is always valid and contains at least one '/'.
switch (m_cookieVariant)
@@ -505,16 +557,16 @@ namespace System.Net
}
// Set the default port if Port attribute was present but had no value.
if (setDefault && (m_portImplicit == false && m_port.Length == 0))
if (setDefault && (m_port_implicit == false && m_port.Length == 0))
{
m_portList = new int[1] { port };
m_port_list = new int[1] { port };
}
if (m_portImplicit == false)
if (m_port_implicit == false)
{
// Port must match against the one from the uri.
valid = false;
foreach (int p in m_portList)
foreach (int p in m_port_list)
{
if (p == port)
{
@@ -565,7 +617,7 @@ namespace System.Net
}
set
{
m_portImplicit = false;
m_port_implicit = false;
if (string.IsNullOrEmpty(value))
{
// "Port" is present but has no value.
@@ -602,7 +654,7 @@ namespace System.Net
portList.Add(port);
}
}
m_portList = portList.ToArray();
m_port_list = portList.ToArray();
m_port = value;
m_version = MaxSupportedVersion;
m_cookieVariant = CookieVariant.Rfc2965;
@@ -616,7 +668,7 @@ namespace System.Net
get
{
// PortList will be null if Port Attribute was omitted in the response.
return m_portList;
return m_port_list;
}
}
@@ -652,7 +704,19 @@ namespace System.Net
}
}
internal CookieVariant Variant
/*
TODO: #13607
VSO 449560
Reflecting on internal method won't work on AOT without rd.xml and DisableReflection
block in toolchain.Networking team will be working on exposing methods from S.Net.Primitive
public, this is a temporary workaround till that happens.
*/
#if uap
public
#else
internal
#endif
CookieVariant Variant
{
get
{
@@ -677,7 +741,7 @@ namespace System.Net
{
get
{
return m_domainImplicit ? Domain : m_domainKey;
return m_domain_implicit ? Domain : m_domainKey;
}
}
@@ -745,14 +809,14 @@ namespace System.Net
if (!Plain)
{
// Add the Path if necessary.
if (!m_pathImplicit && m_path.Length > 0)
if (!m_path_implicit && m_path.Length > 0)
{
sb.Append(SeparatorLiteral + SpecialAttributeLiteral + CookieFields.PathAttributeName + EqualsLiteral); // const strings
sb.Append(m_path);
}
// Add the Domain if necessary.
if (!m_domainImplicit && m_domain.Length > 0)
if (!m_domain_implicit && m_domain.Length > 0)
{
sb.Append(SeparatorLiteral + SpecialAttributeLiteral + CookieFields.DomainAttributeName + EqualsLiteral); // const strings
if (IsQuotedDomain) sb.Append('"');
@@ -762,7 +826,7 @@ namespace System.Net
}
// Add the Port if necessary.
if (!m_portImplicit)
if (!m_port_implicit)
{
sb.Append(SeparatorLiteral + SpecialAttributeLiteral + CookieFields.PortAttributeName); // const strings
if (m_port.Length > 0)
@@ -781,7 +845,19 @@ namespace System.Net
}
}
internal string ToServerString()
/*
TODO: #13607
VSO 449560
Reflecting on internal method won't work on AOT without rd.xml and DisableReflection
block in toolchain.Networking team will be working on exposing methods from S.Net.Primitive
public, this is a temporary workaround till that happens.
*/
#if uap
public
#else
internal
#endif
string ToServerString()
{
string result = Name + EqualsLiteral + Value;
if (m_comment != null && m_comment.Length > 0)
@@ -796,7 +872,7 @@ namespace System.Net
{
result += SeparatorLiteral + CookieFields.DiscardAttributeName;
}
if (!m_domainImplicit && m_domain != null && m_domain.Length > 0)
if (!m_domain_implicit && m_domain != null && m_domain.Length > 0)
{
result += SeparatorLiteral + CookieFields.DomainAttributeName + EqualsLiteral + m_domain;
}
@@ -811,11 +887,11 @@ namespace System.Net
}
result += SeparatorLiteral + CookieFields.MaxAgeAttributeName + EqualsLiteral + seconds.ToString(NumberFormatInfo.InvariantInfo);
}
if (!m_pathImplicit && m_path != null && m_path.Length > 0)
if (!m_path_implicit && m_path != null && m_path.Length > 0)
{
result += SeparatorLiteral + CookieFields.PathAttributeName + EqualsLiteral + m_path;
}
if (!Plain && !m_portImplicit && m_port != null && m_port.Length > 0)
if (!Plain && !m_port_implicit && m_port != null && m_port.Length > 0)
{
// QuotesLiteral are included in _port.
result += SeparatorLiteral + CookieFields.PortAttributeName + EqualsLiteral + m_port;

View File

@@ -4,6 +4,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace System.Net
{
@@ -12,7 +13,7 @@ namespace System.Net
// A list of cookies maintained in Sorted order. Only one cookie with matching Name/Domain/Path
[Serializable]
#if !MONO
[System.Runtime.CompilerServices.TypeForwardedFrom("System, Version=4.0.0.0, PublicKeyToken=b77a5c561934e089")]
[System.Runtime.CompilerServices.TypeForwardedFrom("System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
#endif
public class CookieCollection : ICollection
{
@@ -26,7 +27,8 @@ namespace System.Net
private readonly ArrayList m_list = new ArrayList();
private DateTime m_timeStamp = DateTime.MinValue; // Do not rename (binary serialization)
private int m_version; // Do not rename (binary serialization). This field only exists for netfx serialization compatibility.
private DateTime m_TimeStamp = DateTime.MinValue; // Do not rename (binary serialization)
private bool m_has_other_versions; // Do not rename (binary serialization)
public CookieCollection()
@@ -60,6 +62,12 @@ namespace System.Net
}
}
[OnSerializing]
private void OnSerializing(StreamingContext context)
{
m_version = m_list.Count;
}
public void Add(Cookie cookie)
{
if (cookie == null)
@@ -136,19 +144,19 @@ namespace System.Net
switch (how)
{
case Stamp.Set:
m_timeStamp = DateTime.Now;
m_TimeStamp = DateTime.Now;
break;
case Stamp.SetToMaxUsed:
m_timeStamp = DateTime.MaxValue;
m_TimeStamp = DateTime.MaxValue;
break;
case Stamp.SetToUnused:
m_timeStamp = DateTime.MinValue;
m_TimeStamp = DateTime.MinValue;
break;
case Stamp.Check:
default:
break;
}
return m_timeStamp;
return m_TimeStamp;
}
@@ -162,10 +170,24 @@ namespace System.Net
}
}
// If isStrict == false, assumes that incoming cookie is unique.
// If isStrict == true, replace the cookie if found same with newest Variant.
// Returns 1 if added, 0 if replaced or rejected.
internal int InternalAdd(Cookie cookie, bool isStrict)
/*
TODO: #13607
VSO 449560
Reflecting on internal method won't work on AOT without rd.xml and DisableReflection
block in toolchain.Networking team will be working on exposing methods from S.Net.Primitive
public, this is a temporary workaround till that happens.
*/
#if uap
public
#else
internal
#endif
int InternalAdd(Cookie cookie, bool isStrict)
{
int ret = 1;
if (isStrict)

View File

@@ -2,7 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Net.NetworkInformation;
@@ -89,7 +89,7 @@ namespace System.Net
// Manage cookies for a user (implicit). Based on RFC 2965.
[Serializable]
#if !MONO
[System.Runtime.CompilerServices.TypeForwardedFrom("System, Version=4.0.0.0, PublicKeyToken=b77a5c561934e089")]
[System.Runtime.CompilerServices.TypeForwardedFrom("System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
#endif
public class CookieContainer
{
@@ -102,8 +102,7 @@ namespace System.Net
new HeaderVariantInfo(HttpKnownHeaderNames.SetCookie2, CookieVariant.Rfc2965)
};
// NOTE: all accesses of _domainTable must be performed with _domainTable locked.
private readonly Dictionary<string, PathList> m_domainTable = new Dictionary<string, PathList>(); // Do not rename (binary serialization)
private readonly Hashtable m_domainTable = new Hashtable(); // Do not rename (binary serialization)
private int m_maxCookieSize = DefaultCookieLengthLimit; // Do not rename (binary serialization)
private int m_maxCookies = DefaultCookieLimit; // Do not rename (binary serialization)
private int m_maxCookiesPerDomain = DefaultPerDomainCookieLimit; // Do not rename (binary serialization)
@@ -283,11 +282,12 @@ namespace System.Net
try
{
lock (m_domainTable)
lock (m_domainTable.SyncRoot)
{
if (!m_domainTable.TryGetValue(cookie.DomainKey, out pathList))
pathList = (PathList)m_domainTable[cookie.DomainKey];
if (pathList == null)
{
m_domainTable[cookie.DomainKey] = (pathList = PathList.Create());
m_domainTable[cookie.DomainKey] = (pathList = new PathList());
}
}
int domain_count = pathList.GetCookiesCount();
@@ -295,7 +295,7 @@ namespace System.Net
CookieCollection cookies;
lock (pathList.SyncRoot)
{
cookies = pathList[cookie.Path];
cookies = (CookieCollection)pathList[cookie.Path];
if (cookies == null)
{
@@ -383,27 +383,26 @@ namespace System.Net
// Each domain will be cut accordingly.
remainingFraction = (float)m_maxCookies / (float)m_count;
}
lock (m_domainTable)
lock (m_domainTable.SyncRoot)
{
foreach (KeyValuePair<string, PathList> entry in m_domainTable)
foreach (DictionaryEntry entry in m_domainTable)
{
if (domain == null)
{
tempDomain = entry.Key;
pathList = entry.Value; // Aliasing to trick foreach
tempDomain = (string)entry.Key;
pathList = (PathList)entry.Value; // Aliasing to trick foreach
}
else
{
tempDomain = domain;
m_domainTable.TryGetValue(domain, out pathList);
pathList = (PathList)m_domainTable[domain];
}
domain_count = 0; // Cookies in the domain
lock (pathList.SyncRoot)
{
foreach (KeyValuePair<string, CookieCollection> pair in pathList)
foreach (CookieCollection cc in pathList.Values)
{
CookieCollection cc = pair.Value;
itemp = ExpireCollection(cc);
removed += itemp;
m_count -= itemp; // Update this container's count
@@ -425,23 +424,25 @@ namespace System.Net
if (domain_count > min_count)
{
// This case requires sorting all domain collections by timestamp.
KeyValuePair<DateTime, CookieCollection>[] cookies;
Array cookies;
Array stamps;
lock (pathList.SyncRoot)
{
cookies = new KeyValuePair<DateTime, CookieCollection>[pathList.Count];
foreach (KeyValuePair<string, CookieCollection> pair in pathList)
cookies = Array.CreateInstance(typeof(CookieCollection), pathList.Count);
stamps = Array.CreateInstance(typeof(DateTime), pathList.Count);
foreach (CookieCollection cc in pathList.Values)
{
CookieCollection cc = pair.Value;
cookies[itemp] = new KeyValuePair<DateTime, CookieCollection>(cc.TimeStamp(CookieCollection.Stamp.Check), cc);
stamps.SetValue(cc.TimeStamp(CookieCollection.Stamp.Check), itemp);
cookies.SetValue(cc, itemp);
++itemp;
}
}
Array.Sort(cookies, (a, b) => a.Key.CompareTo(b.Key));
Array.Sort(stamps, cookies);
itemp = 0;
for (int i = 0; i < cookies.Length; ++i)
{
CookieCollection cc = cookies[i].Value;
CookieCollection cc = (CookieCollection)cookies.GetValue(i);
lock (cc)
{
@@ -739,8 +740,8 @@ namespace System.Net
int port = uri.Port;
CookieCollection cookies = null;
List<string> domainAttributeMatchAnyCookieVariant = new List<string>();
List<string> domainAttributeMatchOnlyCookieVariantPlain = null;
var domainAttributeMatchAnyCookieVariant = new System.Collections.Generic.List<string>();
System.Collections.Generic.List<string> domainAttributeMatchOnlyCookieVariantPlain = null;
string fqdnRemote = uri.Host;
@@ -784,7 +785,7 @@ namespace System.Net
{
if (domainAttributeMatchOnlyCookieVariantPlain == null)
{
domainAttributeMatchOnlyCookieVariantPlain = new List<string>();
domainAttributeMatchOnlyCookieVariantPlain = new System.Collections.Generic.List<string>();
}
// These candidates can only match CookieVariant.Plain cookies.
@@ -803,16 +804,17 @@ namespace System.Net
return cookies;
}
private void BuildCookieCollectionFromDomainMatches(Uri uri, bool isSecure, int port, ref CookieCollection cookies, List<string> domainAttribute, bool matchOnlyPlainCookie)
private void BuildCookieCollectionFromDomainMatches(Uri uri, bool isSecure, int port, ref CookieCollection cookies, System.Collections.Generic.List<string> domainAttribute, bool matchOnlyPlainCookie)
{
for (int i = 0; i < domainAttribute.Count; i++)
{
bool found = false;
bool defaultAdded = false;
PathList pathList;
lock (m_domainTable)
lock (m_domainTable.SyncRoot)
{
if (!m_domainTable.TryGetValue(domainAttribute[i], out pathList))
pathList = (PathList)m_domainTable[domainAttribute[i]];
if (pathList == null)
{
continue;
}
@@ -820,14 +822,16 @@ namespace System.Net
lock (pathList.SyncRoot)
{
foreach (KeyValuePair<string, CookieCollection> pair in pathList)
// Manual use of IDictionaryEnumerator instead of foreach to avoid DictionaryEntry box allocations.
IDictionaryEnumerator e = pathList.GetEnumerator();
while (e.MoveNext())
{
string path = pair.Key;
string path = (string)e.Key;
if (uri.AbsolutePath.StartsWith(CookieParser.CheckQuoted(path)))
{
found = true;
CookieCollection cc = pair.Value;
CookieCollection cc = (CookieCollection)e.Value;
cc.TimeStamp(CookieCollection.Stamp.Set);
MergeUpdateCollections(ref cookies, cc, port, isSecure, matchOnlyPlainCookie);
@@ -845,7 +849,7 @@ namespace System.Net
if (!defaultAdded)
{
CookieCollection cc = pathList["/"];
CookieCollection cc = (CookieCollection)pathList["/"];
if (cc != null)
{
@@ -858,7 +862,7 @@ namespace System.Net
// (This is the only place that does domain removal)
if (pathList.Count == 0)
{
lock (m_domainTable)
lock (m_domainTable.SyncRoot)
{
m_domainTable.Remove(domainAttribute[i]);
}
@@ -937,6 +941,7 @@ namespace System.Net
{
throw new ArgumentNullException(nameof(uri));
}
string dummy;
return GetCookieHeader(uri, out dummy);
}
@@ -952,7 +957,7 @@ namespace System.Net
string delimiter = string.Empty;
var builder = StringBuilderCache.Acquire();
StringBuilder builder = StringBuilderCache.Acquire();
for (int i = 0; i < cookies.Count; i++)
{
builder.Append(delimiter);
@@ -984,55 +989,46 @@ namespace System.Net
}
}
// PathList needs to be public in order to maintain binary serialization compatibility as the System shim
// needs to have access to type-forward it.
[Serializable]
internal struct PathList
[System.Runtime.CompilerServices.TypeForwardedFrom("System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public sealed class PathList
{
// Usage of PathList depends on it being shallowly immutable;
// adding any mutable fields to it would result in breaks.
private readonly SortedList<string, CookieCollection> m_list; // Do not rename (binary serialization)
private readonly SortedList m_list = SortedList.Synchronized(new SortedList(PathListComparer.StaticInstance)); // Do not rename (binary serialization)
public static PathList Create() => new PathList(new SortedList<string, CookieCollection>(PathListComparer.StaticInstance));
internal int Count => m_list.Count;
private PathList(SortedList<string, CookieCollection> list)
{
Debug.Assert(list != null, $"{nameof(list)} must not be null.");
m_list = list;
}
public int Count
{
get
{
lock (SyncRoot)
{
return m_list.Count;
}
}
}
public int GetCookiesCount()
internal int GetCookiesCount()
{
int count = 0;
lock (SyncRoot)
{
foreach (KeyValuePair<string, CookieCollection> pair in m_list)
foreach (CookieCollection cc in m_list.Values)
{
CookieCollection cc = pair.Value;
count += cc.Count;
}
}
return count;
}
public CookieCollection this[string s]
internal ICollection Values
{
get
{
return m_list.Values;
}
}
internal object this[string s]
{
get
{
lock (SyncRoot)
{
CookieCollection value;
m_list.TryGetValue(s, out value);
return value;
return m_list[s];
}
}
set
@@ -1045,7 +1041,7 @@ namespace System.Net
}
}
public IEnumerator<KeyValuePair<string, CookieCollection>> GetEnumerator()
internal IDictionaryEnumerator GetEnumerator()
{
lock (SyncRoot)
{
@@ -1053,24 +1049,18 @@ namespace System.Net
}
}
public object SyncRoot
{
get
{
Debug.Assert(m_list != null, $"{nameof(PathList)} should never be default initialized and only ever created with {nameof(Create)}.");
return m_list;
}
}
internal object SyncRoot => m_list.SyncRoot;
[Serializable]
private sealed class PathListComparer : IComparer<string>
[System.Runtime.CompilerServices.TypeForwardedFrom("System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
private sealed class PathListComparer : IComparer
{
internal static readonly PathListComparer StaticInstance = new PathListComparer();
int IComparer<string>.Compare(string x, string y)
int IComparer.Compare(object ol, object or)
{
string pathLeft = CookieParser.CheckQuoted(x);
string pathRight = CookieParser.CheckQuoted(y);
string pathLeft = CookieParser.CheckQuoted((string)ol);
string pathRight = CookieParser.CheckQuoted((string)or);
int ll = pathLeft.Length;
int lr = pathRight.Length;
int length = Math.Min(ll, lr);

View File

@@ -151,7 +151,6 @@ namespace System.Net.Primitives.Functional.Tests
[Theory]
[MemberData(nameof(SetCookiesInvalidData))]
[ActiveIssue("https://github.com/dotnet/corefx/issues/20482", TargetFrameworkMonikers.UapAot)]
public static void SetCookies_InvalidData_Throws(Uri uri, string cookieHeader)
{
CookieContainer cc = new CookieContainer();

View File

@@ -171,7 +171,7 @@ namespace System.Net.Primitives.Functional.Tests
CredentialCache cc = new CredentialCache();
cc.Add(uriPrefix1, authenticationType1, credential1);
Assert.Throws<ArgumentException>(() => cc.Add(uriPrefix1, authenticationType1, credential1));
AssertExtensions.Throws<ArgumentException>(null, () => cc.Add(uriPrefix1, authenticationType1, credential1));
}
[Fact]
@@ -218,7 +218,7 @@ namespace System.Net.Primitives.Functional.Tests
CredentialCache cc = new CredentialCache();
cc.Add(host1, port1, authenticationType1, credential1);
Assert.Throws<ArgumentException>(() => cc.Add(host1, port1, authenticationType1, credential1));
AssertExtensions.Throws<ArgumentException>(null, () => cc.Add(host1, port1, authenticationType1, credential1));
}
[Fact]

View File

@@ -32,12 +32,12 @@ namespace System.Net.Primitives.Functional.Tests
public static void Ctor_HostPortAddressFamily_Invalid()
{
Assert.Throws<ArgumentNullException>(() => new DnsEndPoint(null, 500, AddressFamily.InterNetwork)); //Null host
Assert.Throws<ArgumentException>(() => new DnsEndPoint("", 500, AddressFamily.InterNetwork)); //Empty host
AssertExtensions.Throws<ArgumentException>(null, () => new DnsEndPoint("", 500, AddressFamily.InterNetwork)); //Empty host
Assert.Throws<ArgumentOutOfRangeException>(() => new DnsEndPoint("host", IPEndPoint.MinPort - 1, AddressFamily.InterNetwork)); //Port < min port (0)
Assert.Throws<ArgumentOutOfRangeException>(() => new DnsEndPoint("host", IPEndPoint.MaxPort + 1, AddressFamily.InterNetwork)); //Port > max port (65535)
Assert.Throws<ArgumentException>(() => new DnsEndPoint("host", 500, AddressFamily.AppleTalk
AssertExtensions.Throws<ArgumentException>("addressFamily", () => new DnsEndPoint("host", 500, AddressFamily.AppleTalk
)); //Invalid address family
}

View File

@@ -98,8 +98,8 @@ namespace System.Net.Primitives.Functional.Tests
public static void Create_Set_Invalid()
{
IPEndPoint ep = new IPEndPoint(testIpV41, 500);
Assert.Throws<ArgumentException>(() => ep.Create(new SocketAddress(Sockets.AddressFamily.InterNetworkV6))); //Different address families
Assert.Throws<ArgumentException>(() => ep.Create(new SocketAddress(Sockets.AddressFamily.InterNetwork, 7))); //
AssertExtensions.Throws<ArgumentException>("socketAddress", () => ep.Create(new SocketAddress(Sockets.AddressFamily.InterNetworkV6))); //Different address families
AssertExtensions.Throws<ArgumentException>("socketAddress", () => ep.Create(new SocketAddress(Sockets.AddressFamily.InterNetwork, 7))); //
}
[Fact]

View File

@@ -12,7 +12,8 @@ namespace System.Net.Primitives.Functional.Tests
public class LoggingTest : RemoteExecutorTestBase
{
[Fact]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework | TargetFrameworkMonikers.UapAot, "NetEventSource is only part of .NET Core and requires internal Reflection")]
[ActiveIssue(20470, TargetFrameworkMonikers.UapAot)]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "NetEventSource is only part of .NET Core.")]
public void EventSource_ExistsWithCorrectId()
{
Type esType = typeof(IPAddress).Assembly.GetType("System.Net.NetEventSource", throwOnError: true, ignoreCase: false);
@@ -25,8 +26,8 @@ namespace System.Net.Primitives.Functional.Tests
}
[Fact]
[ActiveIssue(19909, TargetFrameworkMonikers.Uap)]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "NetFramework: NetEventSource is only part of .NET Core;")]
[ActiveIssue(20470, TargetFrameworkMonikers.UapAot)]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "NetEventSource is only part of .NET Core.")]
public void EventSource_EventsRaisedAsExpected()
{
RemoteInvoke(() =>

View File

@@ -27,21 +27,12 @@
<Compile Include="SerializationTest.cs" />
<Compile Include="RequestCachePolicyTest.cs" />
<Compile Include="CookieContainerAddTest.cs" />
<Compile Include="$(CommonTestPath)\System\AssertExtensions.cs">
<Link>Common\System\AssertExtensions.cs</Link>
</Compile>
<Compile Include="$(CommonTestPath)\System\PlatformDetection.cs">
<Link>Common\System\PlatformDetection.cs</Link>
</Compile>
<Compile Include="$(CommonTestPath)\System\Diagnostics\Tracing\TestEventListener.cs">
<Link>Common\System\Diagnostics\Tracing\TestEventListener.cs</Link>
</Compile>
<Compile Include="$(CommonTestPath)\System\Diagnostics\RemoteExecutorTestBase.cs">
<Link>Common\System\Diagnostics\RemoteExecutorTestBase.cs</Link>
</Compile>
<Compile Include="$(CommonTestPath)\System\IO\FileCleanupTestBase.cs">
<Link>Common\System\IO\FileCleanupTestBase.cs</Link>
</Compile>
<Compile Include="$(CommonTestPath)\System\Runtime\Serialization\Formatters\BinaryFormatterHelpers.cs">
<Link>Common\System\Runtime\Serialization\Formatters\BinaryFormatterHelpers.cs</Link>
</Compile>

View File

@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
@@ -251,7 +251,7 @@ namespace System.Net.Primitives.Unit.Tests
container.Add(uri, cookie1);
container.Add(uri, cookie2);
var cookies = container.GetCookies(uri);
CookieCollection cookies = container.GetCookies(uri);
Assert.Equal(2, cookies.Count);
Assert.Equal(OriginalDomain, cookies[CookieName1].Domain);
Assert.Equal(OriginalDomain, cookies[CookieName2].Domain);
@@ -284,7 +284,7 @@ namespace System.Net.Primitives.Unit.Tests
container.Add(new Uri(SchemePrefix + OriginalDomain), cookie1);
var uri = new Uri(SchemePrefix + OriginalDomain);
var cookies = container.GetCookies(uri);
CookieCollection cookies = container.GetCookies(uri);
Assert.Equal(1, cookies.Count);
Assert.Equal(OriginalDomain, cookies[CookieName1].Domain);
@@ -317,7 +317,7 @@ namespace System.Net.Primitives.Unit.Tests
container.Add(new Uri(SchemePrefix + OriginalDomain), cookie1);
var uri = new Uri(SchemePrefix + OriginalDomain);
var cookies = container.GetCookies(uri);
CookieCollection cookies = container.GetCookies(uri);
Assert.Equal(1, cookies.Count);
Assert.Equal(OriginalDomainWithLeadingDot, cookies[CookieName1].Domain);
@@ -348,7 +348,7 @@ namespace System.Net.Primitives.Unit.Tests
[Fact]
public void Ctor_Capacity_Invalid()
{
Assert.Throws<ArgumentException>(() => new CookieContainer(0)); // Capacity <= 0
AssertExtensions.Throws<ArgumentException>("Capacity", () => new CookieContainer(0)); // Capacity <= 0
}
[Fact]
@@ -457,7 +457,7 @@ namespace System.Net.Primitives.Unit.Tests
{
CookieContainer cc = new CookieContainer();
Assert.Throws<ArgumentNullException>(() => cc.Add((Cookie)null)); // Null cookie
Assert.Throws<ArgumentException>(() => cc.Add(new Cookie("name", "value", "", ""))); // Empty domain
AssertExtensions.Throws<ArgumentException>("cookie.Domain", () => cc.Add(new Cookie("name", "value", "", ""))); // Empty domain
cc.MaxCookieSize = 1;
Assert.Throws<CookieException>(() => cc.Add(new Cookie("name", "long-text", "", "contoso.com"))); // Value.Length > MaxCookieSize
@@ -487,11 +487,11 @@ namespace System.Net.Primitives.Unit.Tests
[Fact]
public void Ctor_CapacityPerDomainCapacityMaxCookieSize_Invalid()
{
Assert.Throws<ArgumentException>(() => new CookieContainer(0, 10, 5)); // Capacity <= 0
AssertExtensions.Throws<ArgumentException>("Capacity", () => new CookieContainer(0, 10, 5)); // Capacity <= 0
Assert.Throws<ArgumentOutOfRangeException>(() => new CookieContainer(5, 0, 5)); // Per domain capacity <= 0
Assert.Throws<ArgumentOutOfRangeException>(() => new CookieContainer(5, 10, 5)); // Per domain capacity > Capacity
Assert.Throws<ArgumentException>(() => new CookieContainer(15, 10, 0)); // Max cookie size <= 0
AssertExtensions.Throws<ArgumentException>("MaxCookieSize", () => new CookieContainer(15, 10, 0)); // Max cookie size <= 0
}
[Fact]