@@ -36,54 +36,38 @@ public class Cookie
36
36
private string cookieValue ;
37
37
private string cookiePath ;
38
38
private string cookieDomain ;
39
- private bool isHttpOnly ;
40
39
private string sameSite ;
40
+ private bool isHttpOnly ;
41
41
private bool secure ;
42
42
private DateTime ? cookieExpiry ;
43
43
private readonly string [ ] sameSiteValues = { "Strict" , "Lax" , "None" } ;
44
44
45
+ /// <summary>
46
+ /// Initializes a new instance of the <see cref="Cookie"/> class with a specific name and value.
47
+ /// </summary>
48
+ /// <param name="name">The name of the cookie.</param>
49
+ /// <param name="value">The value of the cookie.</param>
50
+ /// <exception cref="ArgumentException">If the name is <see langword="null"/> or an empty string,
51
+ /// or if it contains a semi-colon.</exception>
52
+ /// <exception cref="ArgumentNullException">If the value is <see langword="null"/>.</exception>
53
+ public Cookie ( string name , string value )
54
+ : this ( name , value , null )
55
+ {
56
+ }
57
+
45
58
/// <summary>
46
59
/// Initializes a new instance of the <see cref="Cookie"/> class with a specific name,
47
- /// value, domain, path and expiration date .
60
+ /// value, and path .
48
61
/// </summary>
49
62
/// <param name="name">The name of the cookie.</param>
50
63
/// <param name="value">The value of the cookie.</param>
51
- /// <param name="domain">The domain of the cookie.</param>
52
64
/// <param name="path">The path of the cookie.</param>
53
- /// <param name="expiry">The expiration date of the cookie.</param>
54
65
/// <exception cref="ArgumentException">If the name is <see langword="null"/> or an empty string,
55
66
/// or if it contains a semi-colon.</exception>
56
67
/// <exception cref="ArgumentNullException">If the value is <see langword="null"/>.</exception>
57
- public Cookie ( string name , string value , string domain , string path , DateTime ? expiry )
68
+ public Cookie ( string name , string value , string path )
69
+ : this ( name , value , path , null )
58
70
{
59
- if ( string . IsNullOrEmpty ( name ) )
60
- {
61
- throw new ArgumentException ( "Cookie name cannot be null or empty string" , "name" ) ;
62
- }
63
-
64
- if ( value == null )
65
- {
66
- throw new ArgumentNullException ( "value" , "Cookie value cannot be null" ) ;
67
- }
68
-
69
- if ( name . IndexOf ( ';' ) != - 1 )
70
- {
71
- throw new ArgumentException ( "Cookie names cannot contain a ';': " + name , "name" ) ;
72
- }
73
-
74
- this . cookieName = name ;
75
- this . cookieValue = value ;
76
- if ( ! string . IsNullOrEmpty ( path ) )
77
- {
78
- this . cookiePath = path ;
79
- }
80
-
81
- this . cookieDomain = StripPort ( domain ) ;
82
-
83
- if ( expiry != null )
84
- {
85
- this . cookieExpiry = expiry ;
86
- }
87
71
}
88
72
89
73
/// <summary>
@@ -102,6 +86,23 @@ public Cookie(string name, string value, string path, DateTime? expiry)
102
86
{
103
87
}
104
88
89
+ /// <summary>
90
+ /// Initializes a new instance of the <see cref="Cookie"/> class with a specific name,
91
+ /// value, domain, path and expiration date.
92
+ /// </summary>
93
+ /// <param name="name">The name of the cookie.</param>
94
+ /// <param name="value">The value of the cookie.</param>
95
+ /// <param name="domain">The domain of the cookie.</param>
96
+ /// <param name="path">The path of the cookie.</param>
97
+ /// <param name="expiry">The expiration date of the cookie.</param>
98
+ /// <exception cref="ArgumentException">If the name is <see langword="null"/> or an empty string,
99
+ /// or if it contains a semi-colon.</exception>
100
+ /// <exception cref="ArgumentNullException">If the value is <see langword="null"/>.</exception>
101
+ public Cookie ( string name , string value , string domain , string path , DateTime ? expiry )
102
+ : this ( name , value , domain , path , expiry , false , false , null )
103
+ {
104
+ }
105
+
105
106
/// <summary>
106
107
/// Initializes a new instance of the <see cref="ReturnedCookie"/> class with a specific name,
107
108
/// value, domain, path and expiration date.
@@ -119,8 +120,36 @@ public Cookie(string name, string value, string path, DateTime? expiry)
119
120
/// <exception cref="ArgumentNullException">If the value or currentUrl is <see langword="null"/>.</exception>
120
121
/// <exception cref="ArgumentNullException">If the same site value is not valid or same site value is "None" but secure is set to false.</exception>
121
122
public Cookie ( string name , string value , string domain , string path , DateTime ? expiry , bool secure , bool isHttpOnly , string sameSite )
122
- : this ( name , value , domain , path , expiry )
123
- {
123
+ {
124
+ if ( string . IsNullOrEmpty ( name ) )
125
+ {
126
+ throw new ArgumentException ( "Cookie name cannot be null or empty string" , "name" ) ;
127
+ }
128
+
129
+ if ( value == null )
130
+ {
131
+ throw new ArgumentNullException ( "value" , "Cookie value cannot be null" ) ;
132
+ }
133
+
134
+ if ( name . IndexOf ( ';' ) != - 1 )
135
+ {
136
+ throw new ArgumentException ( "Cookie names cannot contain a ';': " + name , "name" ) ;
137
+ }
138
+
139
+ this . cookieName = name ;
140
+ this . cookieValue = value ;
141
+ if ( ! string . IsNullOrEmpty ( path ) )
142
+ {
143
+ this . cookiePath = path ;
144
+ }
145
+
146
+ this . cookieDomain = StripPort ( domain ) ;
147
+
148
+ if ( expiry != null )
149
+ {
150
+ this . cookieExpiry = expiry ;
151
+ }
152
+
124
153
this . isHttpOnly = isHttpOnly ;
125
154
this . secure = secure ;
126
155
@@ -131,42 +160,9 @@ public Cookie(string name, string value, string domain, string path, DateTime? e
131
160
throw new ArgumentException ( "Invalid sameSite cookie value. It should either \" Lax\" , \" Strict\" or \" None\" " , "sameSite" ) ;
132
161
}
133
162
134
- if ( "None" . Equals ( sameSite ) && ! this . secure )
135
- {
136
- throw new ArgumentException ( "Invalid cookie configuration: SameSite=None must be Secure" ) ;
137
- }
138
-
139
163
this . sameSite = sameSite ;
140
164
}
141
165
}
142
-
143
- /// <summary>
144
- /// Initializes a new instance of the <see cref="Cookie"/> class with a specific name,
145
- /// value, and path.
146
- /// </summary>
147
- /// <param name="name">The name of the cookie.</param>
148
- /// <param name="value">The value of the cookie.</param>
149
- /// <param name="path">The path of the cookie.</param>
150
- /// <exception cref="ArgumentException">If the name is <see langword="null"/> or an empty string,
151
- /// or if it contains a semi-colon.</exception>
152
- /// <exception cref="ArgumentNullException">If the value is <see langword="null"/>.</exception>
153
- public Cookie ( string name , string value , string path )
154
- : this ( name , value , path , null )
155
- {
156
- }
157
-
158
- /// <summary>
159
- /// Initializes a new instance of the <see cref="Cookie"/> class with a specific name and value.
160
- /// </summary>
161
- /// <param name="name">The name of the cookie.</param>
162
- /// <param name="value">The value of the cookie.</param>
163
- /// <exception cref="ArgumentException">If the name is <see langword="null"/> or an empty string,
164
- /// or if it contains a semi-colon.</exception>
165
- /// <exception cref="ArgumentNullException">If the value is <see langword="null"/>.</exception>
166
- public Cookie ( string name , string value )
167
- : this ( name , value , null , null )
168
- {
169
- }
170
166
171
167
/// <summary>
172
168
/// Gets the name of the cookie.
0 commit comments