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
{
/// <summary>
/// Contains methods to verify the request method of an HTTP request.
/// <summary/>
public static class HttpMethods
{
// 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.
// 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
// 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 Trace = "TRACE";
/// <summary>
/// Verifies the HTTP request method is CONNECT.
/// <summary/>
public static bool IsConnect(string 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)
{
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)
{
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)
{
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)
{
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)
{
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)
{
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)
{
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)
{
return object.ReferenceEquals(Trace, method) || StringComparer.OrdinalIgnoreCase.Equals(Trace, method);

View File

@ -13,6 +13,9 @@ using Microsoft.Extensions.DependencyInjection;
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
{
// 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 DefaultWebSocketManager _websockets;
/// <summary>
/// Initializes a new instance of the DefaultHttpContext class.
/// <summary/>
public DefaultHttpContext()
: this(new FeatureCollection())
{
@ -40,6 +46,9 @@ namespace Microsoft.AspNetCore.Http
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)
{
_features.Initalize(features);
@ -47,6 +56,9 @@ namespace Microsoft.AspNetCore.Http
_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)
{
var revision = features.Revision;
@ -57,6 +69,9 @@ namespace Microsoft.AspNetCore.Http
_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()
{
_features = default;
@ -66,8 +81,14 @@ namespace Microsoft.AspNetCore.Http
_websockets?.Uninitialize();
}
/// <summary>
/// Gets or set the FormOptions for this instance.
/// <summary/>
public FormOptions FormOptions { get; set; }
/// <summary>
/// Gets or sets the IServiceScopeFactory for this instance.
/// <summary/>
public IServiceScopeFactory ServiceScopeFactory { get; set; }
private IItemsFeature ItemsFeature =>
@ -92,16 +113,43 @@ namespace Microsoft.AspNetCore.Http
private IHttpRequestIdentifierFeature RequestIdentifierFeature =>
_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();
/// <summary>
/// Returns the HttpRequest of this instance.
/// <summary/>
public override HttpRequest Request => _request;
/// <summary>
/// Returns the HttpResponse of this instance.
/// <summary/>
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));
/// <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));
/// <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
{
get
@ -117,30 +165,48 @@ namespace Microsoft.AspNetCore.Http
set { HttpAuthenticationFeature.User = value; }
}
/// <summary>
/// Gets or sets the item feature object(s) of this instance.
/// <summary/>
public override IDictionary<object, object> Items
{
get { return ItemsFeature.Items; }
set { ItemsFeature.Items = value; }
}
/// <summary>
/// Gets or sets the service provider feature object of this instance.
/// <summary/>
public override IServiceProvider RequestServices
{
get { return ServiceProvidersFeature.RequestServices; }
set { ServiceProvidersFeature.RequestServices = value; }
}
/// <summary>
/// Gets or sets the cancellation token object of this instance.
/// <summary/>
public override CancellationToken RequestAborted
{
get { return LifetimeFeature.RequestAborted; }
set { LifetimeFeature.RequestAborted = value; }
}
/// <summary>
/// Gets or sets the trace identifier of this instance.
/// <summary/>
public override string TraceIdentifier
{
get { return RequestIdentifierFeature.TraceIdentifier; }
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
{
get

View File

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

View File

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

View File

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

View File

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