@@ -33,18 +33,6 @@ public sealed class Cookie
3333 internal const int MaxSupportedVersion = 1 ;
3434 internal const string MaxSupportedVersionString = "1" ;
3535
36- internal const string CommentAttributeName = "Comment" ;
37- internal const string CommentUrlAttributeName = "CommentURL" ;
38- internal const string DiscardAttributeName = "Discard" ;
39- internal const string DomainAttributeName = "Domain" ;
40- internal const string ExpiresAttributeName = "Expires" ;
41- internal const string MaxAgeAttributeName = "Max-Age" ;
42- internal const string PathAttributeName = "Path" ;
43- internal const string PortAttributeName = "Port" ;
44- internal const string SecureAttributeName = "Secure" ;
45- internal const string VersionAttributeName = "Version" ;
46- internal const string HttpOnlyAttributeName = "HttpOnly" ;
47-
4836 internal const string SeparatorLiteral = "; " ;
4937 internal const string EqualsLiteral = "=" ;
5038 internal const string QuotesLiteral = "\" " ;
@@ -355,7 +343,7 @@ internal bool VerifySetDefaults(CookieVariant variant, Uri uri, bool isLocalDoma
355343 {
356344 if ( shouldThrow )
357345 {
358- throw new CookieException ( SR . Format ( SR . net_cookie_attribute , CommentAttributeName , Comment ) ) ;
346+ throw new CookieException ( SR . Format ( SR . net_cookie_attribute , CookieFields . CommentAttributeName , Comment ) ) ;
359347 }
360348 return false ;
361349 }
@@ -366,7 +354,7 @@ internal bool VerifySetDefaults(CookieVariant variant, Uri uri, bool isLocalDoma
366354 {
367355 if ( shouldThrow )
368356 {
369- throw new CookieException ( SR . Format ( SR . net_cookie_attribute , PathAttributeName , Path ) ) ;
357+ throw new CookieException ( SR . Format ( SR . net_cookie_attribute , CookieFields . PathAttributeName , Path ) ) ;
370358 }
371359 return false ;
372360 }
@@ -395,7 +383,7 @@ internal bool VerifySetDefaults(CookieVariant variant, Uri uri, bool isLocalDoma
395383 {
396384 if ( shouldThrow )
397385 {
398- throw new CookieException ( SR . Format ( SR . net_cookie_attribute , DomainAttributeName , domain == null ? "<null>" : domain ) ) ;
386+ throw new CookieException ( SR . Format ( SR . net_cookie_attribute , CookieFields . DomainAttributeName , domain == null ? "<null>" : domain ) ) ;
399387 }
400388 return false ;
401389 }
@@ -407,7 +395,7 @@ internal bool VerifySetDefaults(CookieVariant variant, Uri uri, bool isLocalDoma
407395 {
408396 if ( shouldThrow )
409397 {
410- throw new CookieException ( SR . Format ( SR . net_cookie_attribute , DomainAttributeName , _domain ) ) ;
398+ throw new CookieException ( SR . Format ( SR . net_cookie_attribute , CookieFields . DomainAttributeName , _domain ) ) ;
411399 }
412400 return false ;
413401 }
@@ -474,7 +462,7 @@ internal bool VerifySetDefaults(CookieVariant variant, Uri uri, bool isLocalDoma
474462 {
475463 if ( shouldThrow )
476464 {
477- throw new CookieException ( SR . Format ( SR . net_cookie_attribute , DomainAttributeName , _domain ) ) ;
465+ throw new CookieException ( SR . Format ( SR . net_cookie_attribute , CookieFields . DomainAttributeName , _domain ) ) ;
478466 }
479467 return false ;
480468 }
@@ -507,7 +495,7 @@ internal bool VerifySetDefaults(CookieVariant variant, Uri uri, bool isLocalDoma
507495 {
508496 if ( shouldThrow )
509497 {
510- throw new CookieException ( SR . Format ( SR . net_cookie_attribute , PathAttributeName , _path ) ) ;
498+ throw new CookieException ( SR . Format ( SR . net_cookie_attribute , CookieFields . PathAttributeName , _path ) ) ;
511499 }
512500 return false ;
513501 }
@@ -535,7 +523,7 @@ internal bool VerifySetDefaults(CookieVariant variant, Uri uri, bool isLocalDoma
535523 {
536524 if ( shouldThrow )
537525 {
538- throw new CookieException ( SR . Format ( SR . net_cookie_attribute , PortAttributeName , _port ) ) ;
526+ throw new CookieException ( SR . Format ( SR . net_cookie_attribute , CookieFields . PortAttributeName , _port ) ) ;
539527 }
540528 return false ;
541529 }
@@ -585,7 +573,7 @@ public string Port
585573 // Parse port list
586574 if ( value [ 0 ] != '\" ' || value [ value . Length - 1 ] != '\" ' )
587575 {
588- throw new CookieException ( SR . Format ( SR . net_cookie_attribute , PortAttributeName , value ) ) ;
576+ throw new CookieException ( SR . Format ( SR . net_cookie_attribute , CookieFields . PortAttributeName , value ) ) ;
589577 }
590578 string [ ] ports = value . Split ( PortSplitDelimiters ) ;
591579
@@ -599,13 +587,13 @@ public string Port
599587 {
600588 if ( ! Int32 . TryParse ( ports [ i ] , out port ) )
601589 {
602- throw new CookieException ( SR . Format ( SR . net_cookie_attribute , PortAttributeName , value ) ) ;
590+ throw new CookieException ( SR . Format ( SR . net_cookie_attribute , CookieFields . PortAttributeName , value ) ) ;
603591 }
604592
605593 // valid values for port 0 - 0xFFFF
606594 if ( ( port < 0 ) || ( port > 0xFFFF ) )
607595 {
608- throw new CookieException ( SR . Format ( SR . net_cookie_attribute , PortAttributeName , value ) ) ;
596+ throw new CookieException ( SR . Format ( SR . net_cookie_attribute , CookieFields . PortAttributeName , value ) ) ;
609597 }
610598
611599 portList . Add ( port ) ;
@@ -742,7 +730,7 @@ internal void ToString(StringBuilder sb)
742730 // Add the Cookie version if necessary.
743731 if ( Version != 0 )
744732 {
745- sb . Append ( SpecialAttributeLiteral + VersionAttributeName + EqualsLiteral ) ; // const strings
733+ sb . Append ( SpecialAttributeLiteral + CookieFields . VersionAttributeName + EqualsLiteral ) ; // const strings
746734 if ( IsQuotedVersion ) sb . Append ( '"' ) ;
747735 sb . Append ( _version . ToString ( NumberFormatInfo . InvariantInfo ) ) ;
748736 if ( IsQuotedVersion ) sb . Append ( '"' ) ;
@@ -757,14 +745,14 @@ internal void ToString(StringBuilder sb)
757745 // Add the Path if necessary.
758746 if ( ! _pathImplicit && _path . Length > 0 )
759747 {
760- sb . Append ( SeparatorLiteral + SpecialAttributeLiteral + PathAttributeName + EqualsLiteral ) ; // const strings
748+ sb . Append ( SeparatorLiteral + SpecialAttributeLiteral + CookieFields . PathAttributeName + EqualsLiteral ) ; // const strings
761749 sb . Append ( _path ) ;
762750 }
763751
764752 // Add the Domain if necessary.
765753 if ( ! _domainImplicit && _domain . Length > 0 )
766754 {
767- sb . Append ( SeparatorLiteral + SpecialAttributeLiteral + DomainAttributeName + EqualsLiteral ) ; // const strings
755+ sb . Append ( SeparatorLiteral + SpecialAttributeLiteral + CookieFields . DomainAttributeName + EqualsLiteral ) ; // const strings
768756 if ( IsQuotedDomain ) sb . Append ( '"' ) ;
769757 sb . Append ( _domain ) ;
770758 if ( IsQuotedDomain ) sb . Append ( '"' ) ;
@@ -774,7 +762,7 @@ internal void ToString(StringBuilder sb)
774762 // Add the Port if necessary.
775763 if ( ! _portImplicit )
776764 {
777- sb . Append ( SeparatorLiteral + SpecialAttributeLiteral + PortAttributeName ) ; // const strings
765+ sb . Append ( SeparatorLiteral + SpecialAttributeLiteral + CookieFields . PortAttributeName ) ; // const strings
778766 if ( _port . Length > 0 )
779767 {
780768 sb . Append ( EqualsLiteral ) ;
@@ -796,19 +784,19 @@ internal string ToServerString()
796784 string result = Name + EqualsLiteral + Value ;
797785 if ( _comment != null && _comment . Length > 0 )
798786 {
799- result += SeparatorLiteral + CommentAttributeName + EqualsLiteral + _comment ;
787+ result += SeparatorLiteral + CookieFields . CommentAttributeName + EqualsLiteral + _comment ;
800788 }
801789 if ( _commentUri != null )
802790 {
803- result += SeparatorLiteral + CommentUrlAttributeName + EqualsLiteral + QuotesLiteral + _commentUri . ToString ( ) + QuotesLiteral ;
791+ result += SeparatorLiteral + CookieFields . CommentUrlAttributeName + EqualsLiteral + QuotesLiteral + _commentUri . ToString ( ) + QuotesLiteral ;
804792 }
805793 if ( _discard )
806794 {
807- result += SeparatorLiteral + DiscardAttributeName ;
795+ result += SeparatorLiteral + CookieFields . DiscardAttributeName ;
808796 }
809797 if ( ! _domainImplicit && _domain != null && _domain . Length > 0 )
810798 {
811- result += SeparatorLiteral + DomainAttributeName + EqualsLiteral + _domain ;
799+ result += SeparatorLiteral + CookieFields . DomainAttributeName + EqualsLiteral + _domain ;
812800 }
813801 if ( Expires != DateTime . MinValue )
814802 {
@@ -819,20 +807,20 @@ internal string ToServerString()
819807 // so that the client will discard the cookie immediately.
820808 seconds = 0 ;
821809 }
822- result += SeparatorLiteral + MaxAgeAttributeName + EqualsLiteral + seconds . ToString ( NumberFormatInfo . InvariantInfo ) ;
810+ result += SeparatorLiteral + CookieFields . MaxAgeAttributeName + EqualsLiteral + seconds . ToString ( NumberFormatInfo . InvariantInfo ) ;
823811 }
824812 if ( ! _pathImplicit && _path != null && _path . Length > 0 )
825813 {
826- result += SeparatorLiteral + PathAttributeName + EqualsLiteral + _path ;
814+ result += SeparatorLiteral + CookieFields . PathAttributeName + EqualsLiteral + _path ;
827815 }
828816 if ( ! Plain && ! _portImplicit && _port != null && _port . Length > 0 )
829817 {
830818 // QuotesLiteral are included in _port.
831- result += SeparatorLiteral + PortAttributeName + EqualsLiteral + _port ;
819+ result += SeparatorLiteral + CookieFields . PortAttributeName + EqualsLiteral + _port ;
832820 }
833821 if ( _version > 0 )
834822 {
835- result += SeparatorLiteral + VersionAttributeName + EqualsLiteral + _version . ToString ( NumberFormatInfo . InvariantInfo ) ;
823+ result += SeparatorLiteral + CookieFields . VersionAttributeName + EqualsLiteral + _version . ToString ( NumberFormatInfo . InvariantInfo ) ;
836824 }
837825 return result == EqualsLiteral ? null : result ;
838826 }
0 commit comments