Skip to content

Commit 06a85e5

Browse files
authored
Dairai/add http class descriptions (#17349)
2 parents 5033efb + d4f380f commit 06a85e5

File tree

7 files changed

+163
-12
lines changed

7 files changed

+163
-12
lines changed

src/Http/Http.Abstractions/src/HttpMethods.cs

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55

66
namespace Microsoft.AspNetCore.Http
77
{
8+
/// <summary>
9+
/// Contains methods to verify the request method of an HTTP request.
10+
/// </summary>
811
public static class HttpMethods
912
{
1013
// We are intentionally using 'static readonly' here instead of 'const'.
11-
// 'const' values would be embedded in to each assembly that used them
14+
// 'const' values would be embedded into each assembly that used them
1215
// and each consuming assembly would have a different 'string' instance.
13-
// Using .'static readonly' means that all consumers get thee exact same
16+
// Using .'static readonly' means that all consumers get these exact same
1417
// 'string' instance, which means the 'ReferenceEquals' checks below work
1518
// and allow us to optimize comparisons when these constants are used.
1619

@@ -25,46 +28,109 @@ public static class HttpMethods
2528
public static readonly string Put = "PUT";
2629
public static readonly string Trace = "TRACE";
2730

31+
/// <summary>
32+
/// Returns a value that indicates if the HTTP request method is CONNECT.
33+
/// </summary>
34+
/// <param name="method">The HTTP request method.</param>
35+
/// <returns>
36+
/// <see langword="true" /> if the method is CONNECT; otherwise, <see langword="false" />.
37+
/// </returns>
2838
public static bool IsConnect(string method)
2939
{
3040
return object.ReferenceEquals(Connect, method) || StringComparer.OrdinalIgnoreCase.Equals(Connect, method);
3141
}
3242

43+
/// <summary>
44+
/// Returns a value that indicates if the HTTP request method is DELETE.
45+
/// </summary>
46+
/// <param name="method">The HTTP request method.</param>
47+
/// <returns>
48+
/// <see langword="true" /> if the method is DELETE; otherwise, <see langword="false" />.
49+
/// </returns>
3350
public static bool IsDelete(string method)
3451
{
3552
return object.ReferenceEquals(Delete, method) || StringComparer.OrdinalIgnoreCase.Equals(Delete, method);
3653
}
3754

55+
/// <summary>
56+
/// Returns a value that indicates if the HTTP request method is GET.
57+
/// </summary>
58+
/// <param name="method">The HTTP request method.</param>
59+
/// <returns>
60+
/// <see langword="true" /> if the method is GET; otherwise, <see langword="false" />.
61+
/// </returns>
3862
public static bool IsGet(string method)
3963
{
4064
return object.ReferenceEquals(Get, method) || StringComparer.OrdinalIgnoreCase.Equals(Get, method);
4165
}
4266

67+
/// <summary>
68+
/// Returns a value that indicates if the HTTP request method is HEAD.
69+
/// </summary>
70+
/// <param name="method">The HTTP request method.</param>
71+
/// <returns>
72+
/// <see langword="true" /> if the method is HEAD; otherwise, <see langword="false" />.
73+
/// </returns>
4374
public static bool IsHead(string method)
4475
{
4576
return object.ReferenceEquals(Head, method) || StringComparer.OrdinalIgnoreCase.Equals(Head, method);
4677
}
4778

79+
/// <summary>
80+
/// Returns a value that indicates if the HTTP request method is OPTIONS.
81+
/// </summary>
82+
/// <param name="method">The HTTP request method.</param>
83+
/// <returns>
84+
/// <see langword="true" /> if the method is OPTIONS; otherwise, <see langword="false" />.
85+
/// </returns>
4886
public static bool IsOptions(string method)
4987
{
5088
return object.ReferenceEquals(Options, method) || StringComparer.OrdinalIgnoreCase.Equals(Options, method);
5189
}
5290

91+
/// <summary>
92+
/// Returns a value that indicates if the HTTP request method is PATCH.
93+
/// </summary>
94+
/// <param name="method">The HTTP request method.</param>
95+
/// <returns>
96+
/// <see langword="true" /> if the method is PATCH; otherwise, <see langword="false" />.
97+
/// </returns>
5398
public static bool IsPatch(string method)
5499
{
55100
return object.ReferenceEquals(Patch, method) || StringComparer.OrdinalIgnoreCase.Equals(Patch, method);
56101
}
57102

103+
/// <summary>
104+
/// Returns a value that indicates if the HTTP request method is POST.
105+
/// </summary>
106+
/// <param name="method">The HTTP request method.</param>
107+
/// <returns>
108+
/// <see langword="true" /> if the method is POST; otherwise, <see langword="false" />.
109+
/// </returns>
58110
public static bool IsPost(string method)
59111
{
60112
return object.ReferenceEquals(Post, method) || StringComparer.OrdinalIgnoreCase.Equals(Post, method);
61113
}
62114

115+
/// <summary>
116+
/// Returns a value that indicates if the HTTP request method is PUT.
117+
/// </summary>
118+
/// <param name="method">The HTTP request method.</param>
119+
/// <returns>
120+
/// <see langword="true" /> if the method is PUT; otherwise, <see langword="false" />.
121+
/// </returns>
63122
public static bool IsPut(string method)
64123
{
65124
return object.ReferenceEquals(Put, method) || StringComparer.OrdinalIgnoreCase.Equals(Put, method);
66125
}
67126

127+
/// <summary>
128+
/// Returns a value that indicates if the HTTP request method is TRACE.
129+
/// </summary>
130+
/// <param name="method">The HTTP request method.</param>
131+
/// <returns>
132+
/// <see langword="true" /> if the method is TRACE; otherwise, <see langword="false" />.
133+
/// </returns>
68134
public static bool IsTrace(string method)
69135
{
70136
return object.ReferenceEquals(Trace, method) || StringComparer.OrdinalIgnoreCase.Equals(Trace, method);

src/Http/Http/src/DefaultHttpContext.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
namespace Microsoft.AspNetCore.Http
1515
{
16+
/// <summary>
17+
/// Represents an implementation of the HTTP Context class.
18+
/// </summary>
1619
public sealed class DefaultHttpContext : HttpContext
1720
{
1821
// Lambdas hoisted to static readonly fields to improve inlining https://github.com/dotnet/roslyn/issues/13624
@@ -32,6 +35,9 @@ public sealed class DefaultHttpContext : HttpContext
3235
private DefaultConnectionInfo _connection;
3336
private DefaultWebSocketManager _websockets;
3437

38+
/// <summary>
39+
/// Initializes a new instance of the <see cref="DefaultHttpContext"/> class.
40+
/// </summary>
3541
public DefaultHttpContext()
3642
: this(new FeatureCollection())
3743
{
@@ -40,13 +46,24 @@ public DefaultHttpContext()
4046
Features.Set<IHttpResponseBodyFeature>(new StreamResponseBodyFeature(Stream.Null));
4147
}
4248

49+
/// <summary>
50+
/// Initializes a new instance of the <see cref="DefaultHttpContext"/> class with provided features.
51+
/// </summary>
52+
/// <param name="features">Initial set of features for the <see cref="DefaultHttpContext"/>.</param>
4353
public DefaultHttpContext(IFeatureCollection features)
4454
{
4555
_features.Initalize(features);
4656
_request = new DefaultHttpRequest(this);
4757
_response = new DefaultHttpResponse(this);
4858
}
4959

60+
/// <summary>
61+
/// Reinitialize the current instant of the class with features passed in.
62+
/// </summary>
63+
/// <remarks>
64+
/// This method allows the consumer to re-use the <see cref="DefaultHttpContext" /> for another request, rather than having to allocate a new instance.
65+
/// </remarks>
66+
/// <param name="features">The new set of features for the <see cref="DefaultHttpContext" />.</param>
5067
public void Initialize(IFeatureCollection features)
5168
{
5269
var revision = features.Revision;
@@ -57,6 +74,9 @@ public void Initialize(IFeatureCollection features)
5774
_websockets?.Initialize(features, revision);
5875
}
5976

77+
/// <summary>
78+
/// Uninitialize all the features in the <see cref="DefaultHttpContext" />.
79+
/// </summary>
6080
public void Uninitialize()
6181
{
6282
_features = default;
@@ -66,8 +86,20 @@ public void Uninitialize()
6686
_websockets?.Uninitialize();
6787
}
6888

89+
/// <summary>
90+
/// Gets or set the <see cref="FormOptions" /> for this instance.
91+
/// </summary>
92+
/// <returns>
93+
/// <see cref="FormOptions"/>
94+
/// </returns>
6995
public FormOptions FormOptions { get; set; }
7096

97+
/// <summary>
98+
/// Gets or sets the <see cref="IServiceScopeFactory" /> for this instance.
99+
/// </summary>
100+
/// <returns>
101+
/// <see cref="IServiceScopeFactory"/>
102+
/// </returns>
71103
public IServiceScopeFactory ServiceScopeFactory { get; set; }
72104

73105
private IItemsFeature ItemsFeature =>
@@ -92,16 +124,22 @@ public void Uninitialize()
92124
private IHttpRequestIdentifierFeature RequestIdentifierFeature =>
93125
_features.Fetch(ref _features.Cache.RequestIdentifier, _newHttpRequestIdentifierFeature);
94126

127+
/// <inheritdoc/>
95128
public override IFeatureCollection Features => _features.Collection ?? ContextDisposed();
96129

130+
/// <inheritdoc/>
97131
public override HttpRequest Request => _request;
98132

133+
/// <inheritdoc/>
99134
public override HttpResponse Response => _response;
100135

136+
/// <inheritdoc/>
101137
public override ConnectionInfo Connection => _connection ?? (_connection = new DefaultConnectionInfo(Features));
102138

139+
/// <inheritdoc/>
103140
public override WebSocketManager WebSockets => _websockets ?? (_websockets = new DefaultWebSocketManager(Features));
104141

142+
/// <inheritdoc/>
105143
public override ClaimsPrincipal User
106144
{
107145
get
@@ -117,30 +155,35 @@ public override ClaimsPrincipal User
117155
set { HttpAuthenticationFeature.User = value; }
118156
}
119157

158+
/// <inheritdoc/>
120159
public override IDictionary<object, object> Items
121160
{
122161
get { return ItemsFeature.Items; }
123162
set { ItemsFeature.Items = value; }
124163
}
125164

165+
/// <inheritdoc/>
126166
public override IServiceProvider RequestServices
127167
{
128168
get { return ServiceProvidersFeature.RequestServices; }
129169
set { ServiceProvidersFeature.RequestServices = value; }
130170
}
131171

172+
/// <inheritdoc/>
132173
public override CancellationToken RequestAborted
133174
{
134175
get { return LifetimeFeature.RequestAborted; }
135176
set { LifetimeFeature.RequestAborted = value; }
136177
}
137178

179+
/// <inheritdoc/>
138180
public override string TraceIdentifier
139181
{
140182
get { return RequestIdentifierFeature.TraceIdentifier; }
141183
set { RequestIdentifierFeature.TraceIdentifier = value; }
142184
}
143185

186+
/// <inheritdoc/>
144187
public override ISession Session
145188
{
146189
get
@@ -166,6 +209,7 @@ public override ISession Session
166209
[EditorBrowsable(EditorBrowsableState.Never)]
167210
public HttpContext HttpContext => this;
168211

212+
/// <inheritdoc/>
169213
public override void Abort()
170214
{
171215
LifetimeFeature.Abort();

src/Http/Http/src/HttpContextAccessor.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55

66
namespace Microsoft.AspNetCore.Http
77
{
8+
/// <summary>
9+
/// Provides an implementation of <see cref="IHttpContextAccessor" /> based on the current execution context.
10+
/// </summary>
811
public class HttpContextAccessor : IHttpContextAccessor
912
{
1013
private static AsyncLocal<HttpContextHolder> _httpContextCurrent = new AsyncLocal<HttpContextHolder>();
1114

15+
/// <inheritdoc/>
1216
public HttpContext HttpContext
1317
{
1418
get

src/Http/Http/src/HttpContextFactory.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,51 @@
88

99
namespace Microsoft.AspNetCore.Http
1010
{
11+
/// <summary>
12+
/// Represents methods used to create an HTTP context object.
13+
/// </summary>
1114
[Obsolete("This is obsolete and will be removed in a future version. Use DefaultHttpContextFactory instead.")]
1215
public class HttpContextFactory : IHttpContextFactory
1316
{
1417
private readonly IHttpContextAccessor _httpContextAccessor;
1518
private readonly FormOptions _formOptions;
1619
private readonly IServiceScopeFactory _serviceScopeFactory;
1720

21+
/// <summary>
22+
/// Initializes a new instance of the HttpContext class with options passed in.
23+
/// </summary>
24+
/// <param name="formOptions">Options to set when instantianting the HTTP context object.</param>
1825
public HttpContextFactory(IOptions<FormOptions> formOptions)
1926
: this(formOptions, serviceScopeFactory: null)
2027
{
2128
}
2229

30+
/// <summary>
31+
/// Initializes a new instance of the DefaultHttpContext class with options passed in.
32+
/// </summary>
33+
/// <param name="formOptions">Options to set when instantianting the HTTP context object.</param>
34+
/// <param name="serviceScopeFactory">Factory object used to create the service scope for the HTTP context.</param>
2335
public HttpContextFactory(IOptions<FormOptions> formOptions, IServiceScopeFactory serviceScopeFactory)
2436
: this(formOptions, serviceScopeFactory, httpContextAccessor: null)
2537
{
2638
}
2739

40+
/// <summary>
41+
/// Initializes a new instance of the DefaultHttpContext class with options passed in.
42+
/// </summary>
43+
/// <param name="formOptions">Options to set when instantianting the HTTP context object.</param>
44+
/// <param name="httpContextAccessor">Object to be used to access the HTTP context instance.</param>
2845
public HttpContextFactory(IOptions<FormOptions> formOptions, IHttpContextAccessor httpContextAccessor)
2946
: this(formOptions, serviceScopeFactory: null, httpContextAccessor: httpContextAccessor)
3047
{
3148
}
3249

50+
/// <summary>
51+
/// Initializes a new instance of the DefaultHttpContext class with options passed in.
52+
/// </summary>
53+
/// <param name="formOptions">Options to set when instantianting the HTTP context object.</param>
54+
/// <param name="serviceScopeFactory">Factory object used to create the service scope for the HTTP context.</param>
55+
/// <param name="httpContextAccessor">Options to set when instantianting the Default HTTP context object.</param>
3356
public HttpContextFactory(IOptions<FormOptions> formOptions, IServiceScopeFactory serviceScopeFactory, IHttpContextAccessor httpContextAccessor)
3457
{
3558
if (formOptions == null)
@@ -47,6 +70,10 @@ public HttpContextFactory(IOptions<FormOptions> formOptions, IServiceScopeFactor
4770
_httpContextAccessor = httpContextAccessor;
4871
}
4972

73+
/// <summary>
74+
/// Initializes a new instance of the DefaultHttpContext class with options passed in.
75+
/// </summary>
76+
/// <param name="featureCollection">Options to set when instantianting the Default HTTP context object.</param>
5077
public HttpContext Create(IFeatureCollection featureCollection)
5178
{
5279
if (featureCollection == null)
@@ -66,6 +93,10 @@ public HttpContext Create(IFeatureCollection featureCollection)
6693
return httpContext;
6794
}
6895

96+
/// <summary>
97+
/// Sets the HTTP context object to null for garbage collection.
98+
/// </summary>
99+
/// <param name="httpContext">HTTP context to dispose.</param>
69100
public void Dispose(HttpContext httpContext)
70101
{
71102
if (_httpContextAccessor != null)

0 commit comments

Comments
 (0)