11
11
12
12
namespace Microsoft . Net . Http . Headers
13
13
{
14
+ /// <summary>
15
+ /// Represents the <c>Cache-Control</c> HTTP header.
16
+ /// </summary>
14
17
public class CacheControlHeaderValue
15
18
{
19
+ /// <summary>
20
+ /// A constant for the <c>public</c> cache-control directive.
21
+ /// </summary>
16
22
public static readonly string PublicString = "public" ;
23
+
24
+ /// <summary>
25
+ /// A constant for the <c>private</c> cache-control directive.
26
+ /// </summary>
17
27
public static readonly string PrivateString = "private" ;
28
+
29
+ /// <summary>
30
+ /// A constant for the <c>max-age</c> cache-control directive.
31
+ /// </summary>
18
32
public static readonly string MaxAgeString = "max-age" ;
33
+
34
+ /// <summary>
35
+ /// A constant for the <c>s-maxage</c> cache-control directive.
36
+ /// </summary>
19
37
public static readonly string SharedMaxAgeString = "s-maxage" ;
38
+
39
+ /// <summary>
40
+ /// A constant for the <c>no-cache</c> cache-control directive.
41
+ /// </summary>
20
42
public static readonly string NoCacheString = "no-cache" ;
43
+
44
+ /// <summary>
45
+ /// A constant for the <c>no-store</c> cache-control directive.
46
+ /// </summary>
21
47
public static readonly string NoStoreString = "no-store" ;
48
+
49
+ /// <summary>
50
+ /// A constant for the <c>max-stale</c> cache-control directive.
51
+ /// </summary>
22
52
public static readonly string MaxStaleString = "max-stale" ;
53
+
54
+ /// <summary>
55
+ /// A constant for the <c>min-fresh</c> cache-control directive.
56
+ /// </summary>
23
57
public static readonly string MinFreshString = "min-fresh" ;
58
+
59
+ /// <summary>
60
+ /// A constant for the <c>no-transform</c> cache-control directive.
61
+ /// </summary>
24
62
public static readonly string NoTransformString = "no-transform" ;
63
+
64
+ /// <summary>
65
+ /// A constant for the <c>only-if-cached</c> cache-control directive.
66
+ /// </summary>
25
67
public static readonly string OnlyIfCachedString = "only-if-cached" ;
68
+
69
+ /// <summary>
70
+ /// A constant for the <c>must-revalidate</c> cache-control directive.
71
+ /// </summary>
26
72
public static readonly string MustRevalidateString = "must-revalidate" ;
73
+
74
+ /// <summary>
75
+ /// A constant for the <c>proxy-revalidate</c> cache-control directive.
76
+ /// </summary>
27
77
public static readonly string ProxyRevalidateString = "proxy-revalidate" ;
28
78
29
79
// The Cache-Control header is special: It is a header supporting a list of values, but we represent the list
@@ -53,17 +103,31 @@ private static readonly HttpHeaderParser<CacheControlHeaderValue> Parser
53
103
private bool _proxyRevalidate ;
54
104
private IList < NameValueHeaderValue > ? _extensions ;
55
105
106
+ /// <summary>
107
+ /// Initializes a new instance of <see cref="CacheControlHeaderValue"/>.
108
+ /// </summary>
56
109
public CacheControlHeaderValue ( )
57
110
{
58
111
// This type is unique in that there is no single required parameter.
59
112
}
60
113
114
+ /// <summary>
115
+ /// Gets or sets a value for the <c>no-cache</c> directive.
116
+ /// <para>
117
+ /// Configuring no-cache indicates that the client must re-validate cached responses with the original server
118
+ /// before using it.
119
+ /// </para>
120
+ /// </summary>
121
+ /// <remarks>See https://tools.ietf.org/html/rfc7234#section-5.2.1.4</remarks>
61
122
public bool NoCache
62
123
{
63
124
get { return _noCache ; }
64
125
set { _noCache = value ; }
65
126
}
66
127
128
+ /// <summary>
129
+ /// Gets a collection of field names in the "no-cache" directive in a cache-control header field on an HTTP response.
130
+ /// </summary>
67
131
public ICollection < StringSegment > NoCacheHeaders
68
132
{
69
133
get
@@ -76,66 +140,140 @@ public ICollection<StringSegment> NoCacheHeaders
76
140
}
77
141
}
78
142
143
+ /// <summary>
144
+ /// Gets or sets a value for the <c>no-store</c> directive.
145
+ /// <para>
146
+ /// Configuring no-store indicates that the response may not be stored in any cache.
147
+ /// </para>
148
+ /// </summary>
149
+ /// <remarks>See https://tools.ietf.org/html/rfc7234#section-5.2.1.5</remarks>
79
150
public bool NoStore
80
151
{
81
152
get { return _noStore ; }
82
153
set { _noStore = value ; }
83
154
}
84
155
156
+ /// <summary>
157
+ /// Gets or sets a value for the <c>max-age</c> directive.
158
+ /// <para>
159
+ /// max-age specifies the maximum amount of time the response is considered fresh.
160
+ /// </para>
161
+ /// </summary>
162
+ /// <remarks>See https://tools.ietf.org/html/rfc7234#section-5.2.1.1</remarks>
85
163
public TimeSpan ? MaxAge
86
164
{
87
165
get { return _maxAge ; }
88
166
set { _maxAge = value ; }
89
167
}
90
168
169
+ /// <summary>
170
+ /// Gets or sets a value for the <c>s-maxage</c> directive.
171
+ /// <para>
172
+ /// Overrides <see cref="MaxAge">max-age</see>, but only for shared caches (such as proxies).
173
+ /// </para>
174
+ /// </summary>
175
+ /// <remarks>See https://tools.ietf.org/html/rfc7234#section-5.2.2.9</remarks>
91
176
public TimeSpan ? SharedMaxAge
92
177
{
93
178
get { return _sharedMaxAge ; }
94
179
set { _sharedMaxAge = value ; }
95
180
}
96
181
182
+ /// <summary>
183
+ /// Gets or sets a value that determines if the <c>max-stale</c> is included.
184
+ /// <para>
185
+ /// <c>max-stale</c> that the client will accept stale responses. The maximum tolerance for staleness
186
+ /// is specified by <see cref="MaxStaleLimit"/>.
187
+ /// </para>
188
+ /// </summary>
189
+ /// <remarks>See https://tools.ietf.org/html/rfc7234#section-5.2.1.2</remarks>
97
190
public bool MaxStale
98
191
{
99
192
get { return _maxStale ; }
100
193
set { _maxStale = value ; }
101
194
}
102
195
196
+ /// <summary>
197
+ /// Gets or sets a value for the <c>max-stale</c> directive.
198
+ /// <para>
199
+ /// Indicates the maximum duration an HTTP client is willing to accept a response that has exceeded its expiration time.
200
+ /// </para>
201
+ /// </summary>
202
+ /// <remarks>See https://tools.ietf.org/html/rfc7234#section-5.2.1.2</remarks>
103
203
public TimeSpan ? MaxStaleLimit
104
204
{
105
205
get { return _maxStaleLimit ; }
106
206
set { _maxStaleLimit = value ; }
107
207
}
108
208
209
+ /// <summary>
210
+ /// Gets or sets a value for the <c>min-fresh</c> directive.
211
+ /// <para>
212
+ /// Indicates the freshness lifetime that an HTTP client is willing to accept a response.
213
+ /// </para>
214
+ /// </summary>
215
+ /// <remarks>See https://tools.ietf.org/html/rfc7234#section-5.2.1.3</remarks>
109
216
public TimeSpan ? MinFresh
110
217
{
111
218
get { return _minFresh ; }
112
219
set { _minFresh = value ; }
113
220
}
114
221
222
+ /// <summary>
223
+ /// Gets or sets a value for the <c>no-transform</c> request directive.
224
+ /// <para>
225
+ /// Forbids intermediate caches or proxies from editing the response payload.
226
+ /// </para>
227
+ /// </summary>
228
+ /// <remarks>See https://tools.ietf.org/html/rfc7234#section-5.2.1.6</remarks>
115
229
public bool NoTransform
116
230
{
117
231
get { return _noTransform ; }
118
232
set { _noTransform = value ; }
119
233
}
120
234
235
+ /// <summary>
236
+ /// Gets or sets a value for the <c>only-if-cached</c> request directive.
237
+ /// <para>
238
+ /// Indicates that the client only wishes to obtain a stored response
239
+ /// </para>
240
+ /// </summary>
241
+ /// <remarks>See https://tools.ietf.org/html/rfc7234#section-5.2.1.7</remarks>
121
242
public bool OnlyIfCached
122
243
{
123
244
get { return _onlyIfCached ; }
124
245
set { _onlyIfCached = value ; }
125
246
}
126
247
248
+ /// <summary>
249
+ /// Gets or sets a value that determines if the <c>public</c> response directive is included.
250
+ /// <para>
251
+ /// Indicates that the response may be stored by any cache.
252
+ /// </para>
253
+ /// </summary>
254
+ /// <remarks>See https://tools.ietf.org/html/rfc7234#section-5.2.2.5</remarks>
127
255
public bool Public
128
256
{
129
257
get { return _public ; }
130
258
set { _public = value ; }
131
259
}
132
260
261
+ /// <summary>
262
+ /// Gets or sets a value that determines if the <c>private</c> response directive is included.
263
+ /// <para>
264
+ /// Indicates that the response may not be stored by a shared cache.
265
+ /// </para>
266
+ /// </summary>
267
+ /// <remarks>See https://tools.ietf.org/html/rfc7234#section-5.2.2.6</remarks>
133
268
public bool Private
134
269
{
135
270
get { return _private ; }
136
271
set { _private = value ; }
137
272
}
138
273
274
+ /// <summary>
275
+ /// Gets a collection of field names in the "private" directive in a cache-control header field on an HTTP response.
276
+ /// </summary>
139
277
public ICollection < StringSegment > PrivateHeaders
140
278
{
141
279
get
@@ -148,18 +286,35 @@ public ICollection<StringSegment> PrivateHeaders
148
286
}
149
287
}
150
288
289
+ /// <summary>
290
+ /// Gets or sets a value that determines if the <c>must-revalidate</c> response directive is included.
291
+ /// <para>
292
+ /// Indicates that caches must revalidate the use of stale caches with the origin server before their use.
293
+ /// </para>
294
+ /// </summary>
295
+ /// <remarks>See https://tools.ietf.org/html/rfc7234#section-5.2.2.1</remarks>
151
296
public bool MustRevalidate
152
297
{
153
298
get { return _mustRevalidate ; }
154
299
set { _mustRevalidate = value ; }
155
300
}
156
301
302
+ /// <summary>
303
+ /// Gets or sets a value that determines if the <c>proxy-validate</c> response directive is included.
304
+ /// <para>
305
+ /// Indicates that shared caches must revalidate the use of stale caches with the origin server before their use.
306
+ /// </para>
307
+ /// </summary>
308
+ /// <remarks>See https://tools.ietf.org/html/rfc7234#section-5.2.2.1</remarks>
157
309
public bool ProxyRevalidate
158
310
{
159
311
get { return _proxyRevalidate ; }
160
312
set { _proxyRevalidate = value ; }
161
313
}
162
314
315
+ /// <summary>
316
+ /// Gets cache-extension tokens, each with an optional assigned value.
317
+ /// </summary>
163
318
public IList < NameValueHeaderValue > Extensions
164
319
{
165
320
get
@@ -172,6 +327,7 @@ public IList<NameValueHeaderValue> Extensions
172
327
}
173
328
}
174
329
330
+ /// <inheritdoc />
175
331
public override string ToString ( )
176
332
{
177
333
var sb = new StringBuilder ( ) ;
@@ -241,6 +397,7 @@ public override string ToString()
241
397
return sb . ToString ( ) ;
242
398
}
243
399
400
+ /// <inheritdoc />
244
401
public override bool Equals ( object ? obj )
245
402
{
246
403
var other = obj as CacheControlHeaderValue ;
@@ -280,6 +437,7 @@ public override bool Equals(object? obj)
280
437
return true ;
281
438
}
282
439
440
+ /// <inheritdoc />
283
441
public override int GetHashCode ( )
284
442
{
285
443
// Use a different bit for bool fields: bool.GetHashCode() will return 0 (false) or 1 (true). So we would
@@ -324,6 +482,11 @@ public override int GetHashCode()
324
482
return result ;
325
483
}
326
484
485
+ /// <summary>
486
+ /// Parses <paramref name="input"/> as a <see cref="CacheControlHeaderValue"/> value.
487
+ /// </summary>
488
+ /// <param name="input">The values to parse.</param>
489
+ /// <returns>The parsed values.</returns>
327
490
public static CacheControlHeaderValue Parse ( StringSegment input )
328
491
{
329
492
var index = 0 ;
@@ -336,6 +499,12 @@ public static CacheControlHeaderValue Parse(StringSegment input)
336
499
return result ;
337
500
}
338
501
502
+ /// <summary>
503
+ /// Attempts to parse the specified <paramref name="input"/> as a <see cref="CacheControlHeaderValue"/>.
504
+ /// </summary>
505
+ /// <param name="input">The value to parse.</param>
506
+ /// <param name="parsedValue">The parsed value.</param>
507
+ /// <returns><see langword="true"/> if input is a valid <see cref="SetCookieHeaderValue"/>, otherwise <see langword="false"/>.</returns>
339
508
public static bool TryParse ( StringSegment input , [ NotNullWhen ( true ) ] out CacheControlHeaderValue ? parsedValue )
340
509
{
341
510
var index = 0 ;
0 commit comments