Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 58 additions & 67 deletions src/System.Net.Http/src/netcore50/System/Net/cookie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Threading;

// The NETNative_SystemNetHttp #define is used in some source files to indicate we are compiling classes
Expand Down Expand Up @@ -221,20 +222,6 @@ public string Domain
}
}

private string _Domain
{
get
{
return (Plain || m_domain_implicit || (m_domain.Length == 0))
? string.Empty
: (SpecialAttributeLiteral
+ DomainAttributeName
+ EqualsLiteral + (IsQuotedDomain ? "\"" : string.Empty)
+ m_domain + (IsQuotedDomain ? "\"" : string.Empty)
);
}
}

internal bool DomainImplicit
{
get
Expand Down Expand Up @@ -325,20 +312,6 @@ public string Path
}
}

private string _Path
{
get
{
return (Plain || m_path_implicit || (m_path.Length == 0))
? string.Empty
: (SpecialAttributeLiteral
+ PathAttributeName
+ EqualsLiteral
+ m_path
);
}
}

internal bool Plain
{
get
Expand Down Expand Up @@ -729,18 +702,6 @@ internal int[] PortList
}
}

private string _Port
{
get
{
return m_port_implicit ? string.Empty :
(SpecialAttributeLiteral
+ PortAttributeName
+ ((m_port.Length == 0) ? string.Empty : (EqualsLiteral + m_port))
);
}
}

/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
Expand Down Expand Up @@ -834,18 +795,6 @@ public int Version
}
}

private string _Version
{
get
{
return (Version == 0) ? string.Empty :
(SpecialAttributeLiteral
+ VersionAttributeName
+ EqualsLiteral + (IsQuotedVersion ? "\"" : string.Empty)
+ m_version.ToString(NumberFormatInfo.InvariantInfo) + (IsQuotedVersion ? "\"" : string.Empty));
}
}

// methods


Expand Down Expand Up @@ -897,23 +846,65 @@ public override int GetHashCode()
/// </devdoc>
public override string ToString()
{
string domain = _Domain;
string path = _Path;
string port = _Port;
string version = _Version;

string result =
((version.Length == 0) ? string.Empty : (version + SeparatorLiteral))
+ Name + EqualsLiteral + Value
+ ((path.Length == 0) ? string.Empty : (SeparatorLiteral + path))
+ ((domain.Length == 0) ? string.Empty : (SeparatorLiteral + domain))
+ ((port.Length == 0) ? string.Empty : (SeparatorLiteral + port))
;
if (result == "=")
var sb = new StringBuilder();
ToString(sb);
return sb.ToString();
}

internal void ToString(StringBuilder sb)
{
int beforeLength = sb.Length;

// Add the Cookie version if necessary.
if (Version != 0)
{
sb.Append(SpecialAttributeLiteral + VersionAttributeName + EqualsLiteral); // const strings
if (IsQuotedVersion) sb.Append('"');
sb.Append(m_version.ToString(NumberFormatInfo.InvariantInfo));
if (IsQuotedVersion) sb.Append('"');
sb.Append(SeparatorLiteral);
}

// Add the Cookie Name=Value pair.
sb.Append(Name).Append(EqualsLiteral).Append(Value);

if (!Plain)
{
// Add the Path if necessary.
if (!m_path_implicit && m_path.Length > 0)
{
sb.Append(SeparatorLiteral + SpecialAttributeLiteral + PathAttributeName + EqualsLiteral); // const strings
sb.Append(m_path);
}

// Add the Domain if necessary.
if (!m_domain_implicit && m_domain.Length > 0)
{
sb.Append(SeparatorLiteral + SpecialAttributeLiteral + DomainAttributeName + EqualsLiteral); // const strings
if (IsQuotedDomain) sb.Append('"');
sb.Append(m_domain);
if (IsQuotedDomain) sb.Append('"');
}
}

// Add the Port if necessary.
if (!m_port_implicit)
{
sb.Append(SeparatorLiteral + SpecialAttributeLiteral + PortAttributeName); // const strings
if (m_port.Length > 0)
{
sb.Append(EqualsLiteral);
sb.Append(m_port);
}
}

// Check to see whether the only thing we added was "=", and if so,
// remove it so that we leave the StringBuilder unchanged in contents.
int afterLength = sb.Length;
if (afterLength == (1 + beforeLength) && sb[beforeLength] == '=')
{
return string.Empty;
sb.Length = beforeLength;
}
return result;
}

internal string ToServerString()
Expand Down
3 changes: 3 additions & 0 deletions src/System.Net.Primitives/src/System.Net.Primitives.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@
<Compile Include="$(CommonPath)\System\Net\NetworkInformation\HostInformation.cs">
<Link>Common\System\Net\NetworkInformation\HostInformation.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\System\IO\StringBuilderCache.cs">
<Link>Common\System\IO\StringBuilderCache.cs</Link>
</Compile>
<!-- Logging -->
<Compile Include="$(CommonPath)\System\Net\Shims\TraceSource.cs">
<Link>Common\System\Net\Shims\TraceSource.cs</Link>
Expand Down
127 changes: 61 additions & 66 deletions src/System.Net.Primitives/src/System/Net/Cookie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
// The .NET Foundation licenses this file to you under the MIT license.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should consider making equivalent changes to the copy of Cookie.cs here:
https://github.com/dotnet/corefx/blob/master/src/System.Net.Http/src/netcore50/System/Net/cookie.cs

Long term....there won't be a copy of the file. But due to the way that netcore50 needs cookie functionality, it needed to duplicate the file for now....could potentially be refactored to common code, etc.

// See the LICENSE file in the project root for more information.

using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Text;
using System.Threading;

// The NETNative_SystemNetHttp #define is used in some source files to indicate we are compiling classes
Expand Down Expand Up @@ -181,19 +182,6 @@ public string Domain
}
}

private string _Domain
{
get
{
return (Plain || _domainImplicit || (_domain.Length == 0))
? string.Empty
: (SpecialAttributeLiteral
+ DomainAttributeName
+ EqualsLiteral + (IsQuotedDomain ? "\"" : string.Empty)
+ _domain + (IsQuotedDomain ? "\"" : string.Empty));
}
}

internal bool DomainImplicit
{
get
Expand Down Expand Up @@ -272,19 +260,6 @@ public string Path
}
}

private string _Path
{
get
{
return (Plain || _pathImplicit || (_path.Length == 0))
? string.Empty
: (SpecialAttributeLiteral
+ PathAttributeName
+ EqualsLiteral
+ _path);
}
}

internal bool Plain
{
get
Expand Down Expand Up @@ -666,17 +641,6 @@ internal int[] PortList
}
}

private string _Port
{
get
{
return _portImplicit ? string.Empty :
(SpecialAttributeLiteral
+ PortAttributeName
+ ((_port.Length == 0) ? string.Empty : (EqualsLiteral + _port)));
}
}

public bool Secure
{
get
Expand Down Expand Up @@ -763,18 +727,6 @@ public int Version
}
}

private string _Version
{
get
{
return (Version == 0) ? string.Empty :
(SpecialAttributeLiteral
+ VersionAttributeName
+ EqualsLiteral + (IsQuotedVersion ? "\"" : string.Empty)
+ _version.ToString(NumberFormatInfo.InvariantInfo) + (IsQuotedVersion ? "\"" : string.Empty));
}
}

public override bool Equals(object comparand)
{
Cookie other = comparand as Cookie;
Expand All @@ -794,22 +746,65 @@ public override int GetHashCode()

public override string ToString()
{
string domain = _Domain;
string path = _Path;
string port = _Port;
string version = _Version;

string result =
((version.Length == 0) ? string.Empty : (version + SeparatorLiteral))
+ Name + EqualsLiteral + Value
+ ((path.Length == 0) ? string.Empty : (SeparatorLiteral + path))
+ ((domain.Length == 0) ? string.Empty : (SeparatorLiteral + domain))
+ ((port.Length == 0) ? string.Empty : (SeparatorLiteral + port));
if (result == "=")
{
return string.Empty;
}
return result;
StringBuilder sb = StringBuilderCache.Acquire();
ToString(sb);
return StringBuilderCache.GetStringAndRelease(sb);
}

internal void ToString(StringBuilder sb)
{
int beforeLength = sb.Length;

// Add the Cookie version if necessary.
if (Version != 0)
{
sb.Append(SpecialAttributeLiteral + VersionAttributeName + EqualsLiteral); // const strings
if (IsQuotedVersion) sb.Append('"');
sb.Append(_version.ToString(NumberFormatInfo.InvariantInfo));
if (IsQuotedVersion) sb.Append('"');
sb.Append(SeparatorLiteral);
}

// Add the Cookie Name=Value pair.
sb.Append(Name).Append(EqualsLiteral).Append(Value);

if (!Plain)
{
// Add the Path if necessary.
if (!_pathImplicit && _path.Length > 0)
{
sb.Append(SeparatorLiteral + SpecialAttributeLiteral + PathAttributeName + EqualsLiteral); // const strings
sb.Append(_path);
}

// Add the Domain if necessary.
if (!_domainImplicit && _domain.Length > 0)
{
sb.Append(SeparatorLiteral + SpecialAttributeLiteral + DomainAttributeName + EqualsLiteral); // const strings
if (IsQuotedDomain) sb.Append('"');
sb.Append(_domain);
if (IsQuotedDomain) sb.Append('"');
}
}

// Add the Port if necessary.
if (!_portImplicit)
{
sb.Append(SeparatorLiteral + SpecialAttributeLiteral + PortAttributeName); // const strings
if (_port.Length > 0)
{
sb.Append(EqualsLiteral);
sb.Append(_port);
}
}

// Check to see whether the only thing we added was "=", and if so,
// remove it so that we leave the StringBuilder unchanged in contents.
int afterLength = sb.Length;
if (afterLength == (1 + beforeLength) && sb[beforeLength] == '=')
{
sb.Length = beforeLength;
}
}

internal string ToServerString()
Expand Down
Loading