Updating descriptions for HTTP classes

#17204
This commit is contained in:
Dairai Nyabando 2019-11-22 00:04:16 -05:00
parent e2def80a0a
commit 66613b194d
6 changed files with 113 additions and 5 deletions

View File

@ -5,12 +5,15 @@ using System;
namespace Microsoft.AspNetCore.Http namespace Microsoft.AspNetCore.Http
{ {
/// <summary>
/// Contains methods to verify the request method of an HTTP request.
/// <summary/>
public static class HttpMethods public static class HttpMethods
{ {
// We are intentionally using 'static readonly' here instead of 'const'. // We are intentionally using 'static readonly' here instead of 'const'.
// 'const' values would be embedded in to each assembly that used them // 'const' values would be embedded into each assembly that used them
// and each consuming assembly would have a different 'string' instance. // and each consuming assembly would have a different 'string' instance.
// Using .'static readonly' means that all consumers get thee exact same // Using .'static readonly' means that all consumers get these exact same
// 'string' instance, which means the 'ReferenceEquals' checks below work // 'string' instance, which means the 'ReferenceEquals' checks below work
// and allow us to optimize comparisons when these constants are used. // and allow us to optimize comparisons when these constants are used.
@ -25,46 +28,73 @@ namespace Microsoft.AspNetCore.Http
public static readonly string Put = "PUT"; public static readonly string Put = "PUT";
public static readonly string Trace = "TRACE"; public static readonly string Trace = "TRACE";
/// <summary>
/// Verifies the HTTP request method is CONNECT.
/// <summary/>
public static bool IsConnect(string method) public static bool IsConnect(string method)
{ {
return object.ReferenceEquals(Connect, method) || StringComparer.OrdinalIgnoreCase.Equals(Connect, method); return object.ReferenceEquals(Connect, method) || StringComparer.OrdinalIgnoreCase.Equals(Connect, method);
} }
/// <summary>
/// Verifies the HTTP request method is DELETE.
/// <summary/>
public static bool IsDelete(string method) public static bool IsDelete(string method)
{ {
return object.ReferenceEquals(Delete, method) || StringComparer.OrdinalIgnoreCase.Equals(Delete, method); return object.ReferenceEquals(Delete, method) || StringComparer.OrdinalIgnoreCase.Equals(Delete, method);
} }
/// <summary>
/// Verifies the HTTP request method is GET.
/// <summary/>
public static bool IsGet(string method) public static bool IsGet(string method)
{ {
return object.ReferenceEquals(Get, method) || StringComparer.OrdinalIgnoreCase.Equals(Get, method); return object.ReferenceEquals(Get, method) || StringComparer.OrdinalIgnoreCase.Equals(Get, method);
} }
/// <summary>
/// Verifies the HTTP request method is HEAD.
/// <summary/>
public static bool IsHead(string method) public static bool IsHead(string method)
{ {
return object.ReferenceEquals(Head, method) || StringComparer.OrdinalIgnoreCase.Equals(Head, method); return object.ReferenceEquals(Head, method) || StringComparer.OrdinalIgnoreCase.Equals(Head, method);
} }
/// <summary>
/// Verifies the HTTP request method is OPTIONS.
/// <summary/>
public static bool IsOptions(string method) public static bool IsOptions(string method)
{ {
return object.ReferenceEquals(Options, method) || StringComparer.OrdinalIgnoreCase.Equals(Options, method); return object.ReferenceEquals(Options, method) || StringComparer.OrdinalIgnoreCase.Equals(Options, method);
} }
/// <summary>
/// Verifies the HTTP request method is PATCH.
/// <summary/>
public static bool IsPatch(string method) public static bool IsPatch(string method)
{ {
return object.ReferenceEquals(Patch, method) || StringComparer.OrdinalIgnoreCase.Equals(Patch, method); return object.ReferenceEquals(Patch, method) || StringComparer.OrdinalIgnoreCase.Equals(Patch, method);
} }
/// <summary>
/// Verifies the HTTP request method is POST.
/// <summary/>
public static bool IsPost(string method) public static bool IsPost(string method)
{ {
return object.ReferenceEquals(Post, method) || StringComparer.OrdinalIgnoreCase.Equals(Post, method); return object.ReferenceEquals(Post, method) || StringComparer.OrdinalIgnoreCase.Equals(Post, method);
} }
/// <summary>
/// Verifies the HTTP request method is PUT.
/// <summary/>
public static bool IsPut(string method) public static bool IsPut(string method)
{ {
return object.ReferenceEquals(Put, method) || StringComparer.OrdinalIgnoreCase.Equals(Put, method); return object.ReferenceEquals(Put, method) || StringComparer.OrdinalIgnoreCase.Equals(Put, method);
} }
/// <summary>
/// Verifies the HTTP request method is TRACE.
/// <summary/>
public static bool IsTrace(string method) public static bool IsTrace(string method)
{ {
return object.ReferenceEquals(Trace, method) || StringComparer.OrdinalIgnoreCase.Equals(Trace, method); return object.ReferenceEquals(Trace, method) || StringComparer.OrdinalIgnoreCase.Equals(Trace, method);

View File

@ -13,6 +13,9 @@ using Microsoft.Extensions.DependencyInjection;
namespace Microsoft.AspNetCore.Http namespace Microsoft.AspNetCore.Http
{ {
/// <summary>
/// Represents an implementation of the HTTP Context class with HTTP-specific information for a request.
/// <summary/>
public sealed class DefaultHttpContext : HttpContext public sealed class DefaultHttpContext : HttpContext
{ {
// Lambdas hoisted to static readonly fields to improve inlining https://github.com/dotnet/roslyn/issues/13624 // Lambdas hoisted to static readonly fields to improve inlining https://github.com/dotnet/roslyn/issues/13624
@ -32,6 +35,9 @@ namespace Microsoft.AspNetCore.Http
private DefaultConnectionInfo _connection; private DefaultConnectionInfo _connection;
private DefaultWebSocketManager _websockets; private DefaultWebSocketManager _websockets;
/// <summary>
/// Initializes a new instance of the DefaultHttpContext class.
/// <summary/>
public DefaultHttpContext() public DefaultHttpContext()
: this(new FeatureCollection()) : this(new FeatureCollection())
{ {
@ -40,6 +46,9 @@ namespace Microsoft.AspNetCore.Http
Features.Set<IHttpResponseBodyFeature>(new StreamResponseBodyFeature(Stream.Null)); Features.Set<IHttpResponseBodyFeature>(new StreamResponseBodyFeature(Stream.Null));
} }
/// <summary>
/// Initializes a new instance of the DefaultHttpContext class with the using a collection of AspNetCore.Http.Features.
/// <summary/>
public DefaultHttpContext(IFeatureCollection features) public DefaultHttpContext(IFeatureCollection features)
{ {
_features.Initalize(features); _features.Initalize(features);
@ -47,6 +56,9 @@ namespace Microsoft.AspNetCore.Http
_response = new DefaultHttpResponse(this); _response = new DefaultHttpResponse(this);
} }
/// <summary>
/// Initialize the current instant of the class with the using a collection of AspNetCore.Http.Features.
/// <summary/>
public void Initialize(IFeatureCollection features) public void Initialize(IFeatureCollection features)
{ {
var revision = features.Revision; var revision = features.Revision;
@ -57,6 +69,9 @@ namespace Microsoft.AspNetCore.Http
_websockets?.Initialize(features, revision); _websockets?.Initialize(features, revision);
} }
/// <summary>
/// Uninitialize the child request, response, connection and websocket object features and reset the class instance features.
/// <summary/>
public void Uninitialize() public void Uninitialize()
{ {
_features = default; _features = default;
@ -66,8 +81,14 @@ namespace Microsoft.AspNetCore.Http
_websockets?.Uninitialize(); _websockets?.Uninitialize();
} }
/// <summary>
/// Gets or set the FormOptions for this instance.
/// <summary/>
public FormOptions FormOptions { get; set; } public FormOptions FormOptions { get; set; }
/// <summary>
/// Gets or sets the IServiceScopeFactory for this instance.
/// <summary/>
public IServiceScopeFactory ServiceScopeFactory { get; set; } public IServiceScopeFactory ServiceScopeFactory { get; set; }
private IItemsFeature ItemsFeature => private IItemsFeature ItemsFeature =>
@ -92,16 +113,43 @@ namespace Microsoft.AspNetCore.Http
private IHttpRequestIdentifierFeature RequestIdentifierFeature => private IHttpRequestIdentifierFeature RequestIdentifierFeature =>
_features.Fetch(ref _features.Cache.RequestIdentifier, _newHttpRequestIdentifierFeature); _features.Fetch(ref _features.Cache.RequestIdentifier, _newHttpRequestIdentifierFeature);
/// <summary>
/// Returns the Features for this instance. If null, an ObjectDisposedException Exceptioon is thrown.
/// <summary/>
public override IFeatureCollection Features => _features.Collection ?? ContextDisposed(); public override IFeatureCollection Features => _features.Collection ?? ContextDisposed();
/// <summary>
/// Returns the HttpRequest of this instance.
/// <summary/>
public override HttpRequest Request => _request; public override HttpRequest Request => _request;
/// <summary>
/// Returns the HttpResponse of this instance.
/// <summary/>
public override HttpResponse Response => _response; public override HttpResponse Response => _response;
/// <summary>
/// Returns the connection information of this instance.
/// <summary/>
/// <remarks>
/// If the Connection is null, a new DefaultConnectionInfo object is instantiated using the Features collection of this instance.
/// <remarks/>
public override ConnectionInfo Connection => _connection ?? (_connection = new DefaultConnectionInfo(Features)); public override ConnectionInfo Connection => _connection ?? (_connection = new DefaultConnectionInfo(Features));
/// <summary>
/// Returns the Web Socket Manager of this instance.
/// <summary/>
/// <remarks>
/// If the Connection is null, a new DefaultWebSocketManager object is instantiated using the Features collection of this instance.
/// <remarks/>
public override WebSocketManager WebSockets => _websockets ?? (_websockets = new DefaultWebSocketManager(Features)); public override WebSocketManager WebSockets => _websockets ?? (_websockets = new DefaultWebSocketManager(Features));
/// <summary>
/// Gets or sets the claims principal of this instance.
/// <summary/>
/// <remarks>
/// If the ClaimsPrincipal object is null, a new ClaimsPrincipal object is instantiated.
/// <remarks/>
public override ClaimsPrincipal User public override ClaimsPrincipal User
{ {
get get
@ -117,30 +165,48 @@ namespace Microsoft.AspNetCore.Http
set { HttpAuthenticationFeature.User = value; } set { HttpAuthenticationFeature.User = value; }
} }
/// <summary>
/// Gets or sets the item feature object(s) of this instance.
/// <summary/>
public override IDictionary<object, object> Items public override IDictionary<object, object> Items
{ {
get { return ItemsFeature.Items; } get { return ItemsFeature.Items; }
set { ItemsFeature.Items = value; } set { ItemsFeature.Items = value; }
} }
/// <summary>
/// Gets or sets the service provider feature object of this instance.
/// <summary/>
public override IServiceProvider RequestServices public override IServiceProvider RequestServices
{ {
get { return ServiceProvidersFeature.RequestServices; } get { return ServiceProvidersFeature.RequestServices; }
set { ServiceProvidersFeature.RequestServices = value; } set { ServiceProvidersFeature.RequestServices = value; }
} }
/// <summary>
/// Gets or sets the cancellation token object of this instance.
/// <summary/>
public override CancellationToken RequestAborted public override CancellationToken RequestAborted
{ {
get { return LifetimeFeature.RequestAborted; } get { return LifetimeFeature.RequestAborted; }
set { LifetimeFeature.RequestAborted = value; } set { LifetimeFeature.RequestAborted = value; }
} }
/// <summary>
/// Gets or sets the trace identifier of this instance.
/// <summary/>
public override string TraceIdentifier public override string TraceIdentifier
{ {
get { return RequestIdentifierFeature.TraceIdentifier; } get { return RequestIdentifierFeature.TraceIdentifier; }
set { RequestIdentifierFeature.TraceIdentifier = value; } set { RequestIdentifierFeature.TraceIdentifier = value; }
} }
/// <summary>
/// Gets or sets the session of this instance.
/// <summary/>
/// <remarks>
/// If session feature has not been set, an Invalid Operation Exception is thrown.
/// <remarks/>
public override ISession Session public override ISession Session
{ {
get get

View File

@ -5,10 +5,16 @@ using System.Threading;
namespace Microsoft.AspNetCore.Http namespace Microsoft.AspNetCore.Http
{ {
/// <summary>
/// Represents the properties and methods used to keep access the current HTTP context.
/// <summary/>
public class HttpContextAccessor : IHttpContextAccessor public class HttpContextAccessor : IHttpContextAccessor
{ {
private static AsyncLocal<HttpContextHolder> _httpContextCurrent = new AsyncLocal<HttpContextHolder>(); private static AsyncLocal<HttpContextHolder> _httpContextCurrent = new AsyncLocal<HttpContextHolder>();
/// <summary>
/// Gets or sets the HTTP context.
/// <summary/>
public HttpContext HttpContext public HttpContext HttpContext
{ {
get get

View File

@ -13,6 +13,9 @@ using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNetCore.HttpsPolicy namespace Microsoft.AspNetCore.HttpsPolicy
{ {
/// <summary>
/// Provides functionality to redirect client requests to an address that uses the HTTPS protocol.
/// </summary>
public class HttpsRedirectionMiddleware public class HttpsRedirectionMiddleware
{ {
private const int PortNotFound = -1; private const int PortNotFound = -1;
@ -26,7 +29,7 @@ namespace Microsoft.AspNetCore.HttpsPolicy
private readonly ILogger _logger; private readonly ILogger _logger;
/// <summary> /// <summary>
/// Initializes the HttpsRedirectionMiddleware /// Initializes the HttpsRedirectionMiddleware.
/// </summary> /// </summary>
/// <param name="next"></param> /// <param name="next"></param>
/// <param name="options"></param> /// <param name="options"></param>
@ -56,7 +59,7 @@ namespace Microsoft.AspNetCore.HttpsPolicy
} }
/// <summary> /// <summary>
/// Initializes the HttpsRedirectionMiddleware /// Initializes the HttpsRedirectionMiddleware.
/// </summary> /// </summary>
/// <param name="next"></param> /// <param name="next"></param>
/// <param name="options"></param> /// <param name="options"></param>

View File

@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Http;
namespace Microsoft.AspNetCore.HttpsPolicy namespace Microsoft.AspNetCore.HttpsPolicy
{ {
/// <summary> /// <summary>
/// Options for the HttpsRedirection middleware /// Options for the HttpsRedirection middleware.
/// </summary> /// </summary>
public class HttpsRedirectionOptions public class HttpsRedirectionOptions
{ {

View File

@ -9,6 +9,9 @@ using Microsoft.Extensions.Options;
namespace Microsoft.AspNetCore.Hosting namespace Microsoft.AspNetCore.Hosting
{ {
/// <summary>
/// Provides extensions method to use Http.sys as the server for the web host.
/// </summary>
public static class WebHostBuilderHttpSysExtensions public static class WebHostBuilderHttpSysExtensions
{ {
/// <summary> /// <summary>