Skip to content

Commit 8df66d1

Browse files
authored
Add XML doc comments for Microsoft.Net.Http.Headers (#28415)
* Enable missing doc comments to appear as warnings when building locally. * Update nullability bug that I noticed in RangeConditionHeaderValue
1 parent 3017502 commit 8df66d1

21 files changed

+995
-102
lines changed

Directory.Build.props

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,11 @@
100100

101101
<!-- Warnings and errors -->
102102
<PropertyGroup>
103+
<!-- Ensure API docs are available. -->
104+
<NoWarn>$(NoWarn.Replace('1591', ''))</NoWarn>
105+
103106
<!-- For local builds, don't make missing XML docs a fatal build error, but still surface so we have visibility into undocumented APIs. -->
104107
<WarningsNotAsErrors Condition=" '$(ContinuousIntegrationBuild)' != 'true' ">$(WarningsNotAsErrors);CS1591</WarningsNotAsErrors>
105-
<!-- For CI builds, ensure API docs are available. -->
106-
<NoWarn Condition=" '$(ContinuousIntegrationBuild)' == 'true' ">$(NoWarn.Replace('1591', ''))</NoWarn>
107108

108109
<!-- xUnit1004 = warns about skipped tests. Make this a non-fatal build warning. -->
109110
<WarningsNotAsErrors>$(WarningsNotAsErrors);xUnit1004</WarningsNotAsErrors>

src/Http/Headers/src/CacheControlHeaderValue.cs

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,69 @@
1111

1212
namespace Microsoft.Net.Http.Headers
1313
{
14+
/// <summary>
15+
/// Represents the <c>Cache-Control</c> HTTP header.
16+
/// </summary>
1417
public class CacheControlHeaderValue
1518
{
19+
/// <summary>
20+
/// A constant for the <c>public</c> cache-control directive.
21+
/// </summary>
1622
public static readonly string PublicString = "public";
23+
24+
/// <summary>
25+
/// A constant for the <c>private</c> cache-control directive.
26+
/// </summary>
1727
public static readonly string PrivateString = "private";
28+
29+
/// <summary>
30+
/// A constant for the <c>max-age</c> cache-control directive.
31+
/// </summary>
1832
public static readonly string MaxAgeString = "max-age";
33+
34+
/// <summary>
35+
/// A constant for the <c>s-maxage</c> cache-control directive.
36+
/// </summary>
1937
public static readonly string SharedMaxAgeString = "s-maxage";
38+
39+
/// <summary>
40+
/// A constant for the <c>no-cache</c> cache-control directive.
41+
/// </summary>
2042
public static readonly string NoCacheString = "no-cache";
43+
44+
/// <summary>
45+
/// A constant for the <c>no-store</c> cache-control directive.
46+
/// </summary>
2147
public static readonly string NoStoreString = "no-store";
48+
49+
/// <summary>
50+
/// A constant for the <c>max-stale</c> cache-control directive.
51+
/// </summary>
2252
public static readonly string MaxStaleString = "max-stale";
53+
54+
/// <summary>
55+
/// A constant for the <c>min-fresh</c> cache-control directive.
56+
/// </summary>
2357
public static readonly string MinFreshString = "min-fresh";
58+
59+
/// <summary>
60+
/// A constant for the <c>no-transform</c> cache-control directive.
61+
/// </summary>
2462
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>
2567
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>
2672
public static readonly string MustRevalidateString = "must-revalidate";
73+
74+
/// <summary>
75+
/// A constant for the <c>proxy-revalidate</c> cache-control directive.
76+
/// </summary>
2777
public static readonly string ProxyRevalidateString = "proxy-revalidate";
2878

2979
// 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
53103
private bool _proxyRevalidate;
54104
private IList<NameValueHeaderValue>? _extensions;
55105

106+
/// <summary>
107+
/// Initializes a new instance of <see cref="CacheControlHeaderValue"/>.
108+
/// </summary>
56109
public CacheControlHeaderValue()
57110
{
58111
// This type is unique in that there is no single required parameter.
59112
}
60113

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>
61122
public bool NoCache
62123
{
63124
get { return _noCache; }
64125
set { _noCache = value; }
65126
}
66127

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>
67131
public ICollection<StringSegment> NoCacheHeaders
68132
{
69133
get
@@ -76,66 +140,140 @@ public ICollection<StringSegment> NoCacheHeaders
76140
}
77141
}
78142

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>
79150
public bool NoStore
80151
{
81152
get { return _noStore; }
82153
set { _noStore = value; }
83154
}
84155

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>
85163
public TimeSpan? MaxAge
86164
{
87165
get { return _maxAge; }
88166
set { _maxAge = value; }
89167
}
90168

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>
91176
public TimeSpan? SharedMaxAge
92177
{
93178
get { return _sharedMaxAge; }
94179
set { _sharedMaxAge = value; }
95180
}
96181

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>
97190
public bool MaxStale
98191
{
99192
get { return _maxStale; }
100193
set { _maxStale = value; }
101194
}
102195

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>
103203
public TimeSpan? MaxStaleLimit
104204
{
105205
get { return _maxStaleLimit; }
106206
set { _maxStaleLimit = value; }
107207
}
108208

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>
109216
public TimeSpan? MinFresh
110217
{
111218
get { return _minFresh; }
112219
set { _minFresh = value; }
113220
}
114221

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>
115229
public bool NoTransform
116230
{
117231
get { return _noTransform; }
118232
set { _noTransform = value; }
119233
}
120234

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>
121242
public bool OnlyIfCached
122243
{
123244
get { return _onlyIfCached; }
124245
set { _onlyIfCached = value; }
125246
}
126247

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>
127255
public bool Public
128256
{
129257
get { return _public; }
130258
set { _public = value; }
131259
}
132260

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>
133268
public bool Private
134269
{
135270
get { return _private; }
136271
set { _private = value; }
137272
}
138273

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>
139277
public ICollection<StringSegment> PrivateHeaders
140278
{
141279
get
@@ -148,18 +286,35 @@ public ICollection<StringSegment> PrivateHeaders
148286
}
149287
}
150288

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>
151296
public bool MustRevalidate
152297
{
153298
get { return _mustRevalidate; }
154299
set { _mustRevalidate = value; }
155300
}
156301

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>
157309
public bool ProxyRevalidate
158310
{
159311
get { return _proxyRevalidate; }
160312
set { _proxyRevalidate = value; }
161313
}
162314

315+
/// <summary>
316+
/// Gets cache-extension tokens, each with an optional assigned value.
317+
/// </summary>
163318
public IList<NameValueHeaderValue> Extensions
164319
{
165320
get
@@ -172,6 +327,7 @@ public IList<NameValueHeaderValue> Extensions
172327
}
173328
}
174329

330+
/// <inheritdoc />
175331
public override string ToString()
176332
{
177333
var sb = new StringBuilder();
@@ -241,6 +397,7 @@ public override string ToString()
241397
return sb.ToString();
242398
}
243399

400+
/// <inheritdoc />
244401
public override bool Equals(object? obj)
245402
{
246403
var other = obj as CacheControlHeaderValue;
@@ -280,6 +437,7 @@ public override bool Equals(object? obj)
280437
return true;
281438
}
282439

440+
/// <inheritdoc />
283441
public override int GetHashCode()
284442
{
285443
// 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()
324482
return result;
325483
}
326484

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>
327490
public static CacheControlHeaderValue Parse(StringSegment input)
328491
{
329492
var index = 0;
@@ -336,6 +499,12 @@ public static CacheControlHeaderValue Parse(StringSegment input)
336499
return result;
337500
}
338501

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>
339508
public static bool TryParse(StringSegment input, [NotNullWhen(true)] out CacheControlHeaderValue? parsedValue)
340509
{
341510
var index = 0;

0 commit comments

Comments
 (0)