diff --git a/src/Http/Http.Abstractions/src/HttpContext.cs b/src/Http/Http.Abstractions/src/HttpContext.cs
index 60c938db0a13..c5416cc0b95b 100644
--- a/src/Http/Http.Abstractions/src/HttpContext.cs
+++ b/src/Http/Http.Abstractions/src/HttpContext.cs
@@ -40,14 +40,6 @@ public abstract class HttpContext
///
public abstract WebSocketManager WebSockets { get; }
- ///
- /// This is obsolete and will be removed in a future version.
- /// The recommended alternative is to use Microsoft.AspNetCore.Authentication.AuthenticationHttpContextExtensions.
- /// See https://go.microsoft.com/fwlink/?linkid=845470.
- ///
- [Obsolete("This is obsolete and will be removed in a future version. The recommended alternative is to use Microsoft.AspNetCore.Authentication.AuthenticationHttpContextExtensions. See https://go.microsoft.com/fwlink/?linkid=845470.")]
- public abstract AuthenticationManager Authentication { get; }
-
///
/// Gets or sets the user for this request.
///
diff --git a/src/Http/Http/src/Authentication/DefaultAuthenticationManager.cs b/src/Http/Http/src/Authentication/DefaultAuthenticationManager.cs
deleted file mode 100644
index 9f4121f4cb38..000000000000
--- a/src/Http/Http/src/Authentication/DefaultAuthenticationManager.cs
+++ /dev/null
@@ -1,184 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Security.Claims;
-using System.Threading.Tasks;
-using Microsoft.AspNetCore.Http.Features;
-using Microsoft.AspNetCore.Http.Features.Authentication;
-
-namespace Microsoft.AspNetCore.Http.Authentication.Internal
-{
- [Obsolete("This is obsolete and will be removed in a future version. See https://go.microsoft.com/fwlink/?linkid=845470.")]
- public class DefaultAuthenticationManager : AuthenticationManager
- {
- // Lambda hoisted to static readonly field to improve inlining https://github.com/dotnet/roslyn/issues/13624
- private readonly static Func _newAuthenticationFeature = f => new HttpAuthenticationFeature();
-
- private HttpContext _context;
- private FeatureReferences _features;
-
- public DefaultAuthenticationManager(HttpContext context)
- {
- Initialize(context);
- }
-
- public virtual void Initialize(HttpContext context)
- {
- _context = context;
- _features = new FeatureReferences(context.Features);
- }
-
- public virtual void Uninitialize()
- {
- _features = default(FeatureReferences);
- }
-
- public override HttpContext HttpContext => _context;
-
- private IHttpAuthenticationFeature HttpAuthenticationFeature =>
- _features.Fetch(ref _features.Cache, _newAuthenticationFeature);
-
- public override IEnumerable GetAuthenticationSchemes()
- {
-#pragma warning disable CS0618 // Type or member is obsolete
- var handler = HttpAuthenticationFeature.Handler;
-#pragma warning restore CS0618 // Type or member is obsolete
- if (handler == null)
- {
- return new AuthenticationDescription[0];
- }
-
- var describeContext = new DescribeSchemesContext();
- handler.GetDescriptions(describeContext);
- return describeContext.Results.Select(description => new AuthenticationDescription(description));
- }
-
- // Remove once callers have been switched to GetAuthenticateInfoAsync
- public override async Task AuthenticateAsync(AuthenticateContext context)
- {
- if (context == null)
- {
- throw new ArgumentNullException(nameof(context));
- }
-
-#pragma warning disable CS0618 // Type or member is obsolete
- var handler = HttpAuthenticationFeature.Handler;
-#pragma warning restore CS0618 // Type or member is obsolete
- if (handler != null)
- {
- await handler.AuthenticateAsync(context);
- }
-
- if (!context.Accepted)
- {
- throw new InvalidOperationException($"No authentication handler is configured to authenticate for the scheme: {context.AuthenticationScheme}");
- }
- }
-
- public override async Task GetAuthenticateInfoAsync(string authenticationScheme)
- {
- if (authenticationScheme == null)
- {
- throw new ArgumentNullException(nameof(authenticationScheme));
- }
-
-#pragma warning disable CS0618 // Type or member is obsolete
- var handler = HttpAuthenticationFeature.Handler;
-#pragma warning restore CS0618 // Type or member is obsolete
- var context = new AuthenticateContext(authenticationScheme);
- if (handler != null)
- {
- await handler.AuthenticateAsync(context);
- }
-
- if (!context.Accepted)
- {
- throw new InvalidOperationException($"No authentication handler is configured to authenticate for the scheme: {context.AuthenticationScheme}");
- }
-
- return new AuthenticateInfo
- {
- Principal = context.Principal,
- Properties = new AuthenticationProperties(context.Properties),
- Description = new AuthenticationDescription(context.Description)
- };
- }
-
- public override async Task ChallengeAsync(string authenticationScheme, AuthenticationProperties properties, ChallengeBehavior behavior)
- {
- if (string.IsNullOrEmpty(authenticationScheme))
- {
- throw new ArgumentException(nameof(authenticationScheme));
- }
-
-#pragma warning disable CS0618 // Type or member is obsolete
- var handler = HttpAuthenticationFeature.Handler;
-#pragma warning restore CS0618 // Type or member is obsolete
-
- var challengeContext = new ChallengeContext(authenticationScheme, properties?.Items, behavior);
- if (handler != null)
- {
- await handler.ChallengeAsync(challengeContext);
- }
-
- if (!challengeContext.Accepted)
- {
- throw new InvalidOperationException($"No authentication handler is configured to handle the scheme: {authenticationScheme}");
- }
- }
-
- public override async Task SignInAsync(string authenticationScheme, ClaimsPrincipal principal, AuthenticationProperties properties)
- {
- if (string.IsNullOrEmpty(authenticationScheme))
- {
- throw new ArgumentException(nameof(authenticationScheme));
- }
-
- if (principal == null)
- {
- throw new ArgumentNullException(nameof(principal));
- }
-
-#pragma warning disable CS0618 // Type or member is obsolete
- var handler = HttpAuthenticationFeature.Handler;
-#pragma warning restore CS0618 // Type or member is obsolete
-
- var signInContext = new SignInContext(authenticationScheme, principal, properties?.Items);
- if (handler != null)
- {
- await handler.SignInAsync(signInContext);
- }
-
- if (!signInContext.Accepted)
- {
- throw new InvalidOperationException($"No authentication handler is configured to handle the scheme: {authenticationScheme}");
- }
- }
-
- public override async Task SignOutAsync(string authenticationScheme, AuthenticationProperties properties)
- {
- if (string.IsNullOrEmpty(authenticationScheme))
- {
- throw new ArgumentException(nameof(authenticationScheme));
- }
-
-#pragma warning disable CS0618 // Type or member is obsolete
- var handler = HttpAuthenticationFeature.Handler;
-#pragma warning restore CS0618 // Type or member is obsolete
-
- var signOutContext = new SignOutContext(authenticationScheme, properties?.Items);
- if (handler != null)
- {
- await handler.SignOutAsync(signOutContext);
- }
-
- if (!signOutContext.Accepted)
- {
- throw new InvalidOperationException($"No authentication handler is configured to handle the scheme: {authenticationScheme}");
- }
- }
- }
-}
diff --git a/src/Http/Http/src/DefaultHttpContext.cs b/src/Http/Http/src/DefaultHttpContext.cs
index d02ad6322bfc..7a03c7a3acd6 100644
--- a/src/Http/Http/src/DefaultHttpContext.cs
+++ b/src/Http/Http/src/DefaultHttpContext.cs
@@ -5,15 +5,13 @@
using System.Collections.Generic;
using System.Security.Claims;
using System.Threading;
-using Microsoft.AspNetCore.Http.Authentication;
-using Microsoft.AspNetCore.Http.Authentication.Internal;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Http.Features.Authentication;
using Microsoft.AspNetCore.Http.Internal;
namespace Microsoft.AspNetCore.Http
{
- public class DefaultHttpContext : HttpContext
+ public sealed class DefaultHttpContext : HttpContext
{
// Lambdas hoisted to static readonly fields to improve inlining https://github.com/dotnet/roslyn/issues/13624
private readonly static Func _newItemsFeature = f => new ItemsFeature();
@@ -26,15 +24,11 @@ public class DefaultHttpContext : HttpContext
private FeatureReferences _features;
- private HttpRequest _request;
- private HttpResponse _response;
+ private readonly DefaultHttpRequest _request;
+ private readonly DefaultHttpResponse _response;
-#pragma warning disable CS0618 // Type or member is obsolete
- private AuthenticationManager _authenticationManager;
-#pragma warning restore CS0618 // Type or member is obsolete
-
- private ConnectionInfo _connection;
- private WebSocketManager _websockets;
+ private DefaultConnectionInfo _connection;
+ private DefaultWebSocketManager _websockets;
public DefaultHttpContext()
: this(new FeatureCollection())
@@ -45,46 +39,27 @@ public DefaultHttpContext()
public DefaultHttpContext(IFeatureCollection features)
{
- Initialize(features);
+ _features = new FeatureReferences(features);
+ _request = new DefaultHttpRequest(this);
+ _response = new DefaultHttpResponse(this);
}
- public virtual void Initialize(IFeatureCollection features)
+ public void Initialize(IFeatureCollection features)
{
_features = new FeatureReferences(features);
- _request = InitializeHttpRequest();
- _response = InitializeHttpResponse();
+ _request.Initialize();
+ _response.Initialize();
+ _connection?.Initialize(features);
+ _websockets?.Initialize(features);
}
- public virtual void Uninitialize()
+ public void Uninitialize()
{
- _features = default(FeatureReferences);
- if (_request != null)
- {
- UninitializeHttpRequest(_request);
- _request = null;
- }
- if (_response != null)
- {
- UninitializeHttpResponse(_response);
- _response = null;
- }
- if (_authenticationManager != null)
- {
-#pragma warning disable CS0618 // Type or member is obsolete
- UninitializeAuthenticationManager(_authenticationManager);
-#pragma warning restore CS0618 // Type or member is obsolete
- _authenticationManager = null;
- }
- if (_connection != null)
- {
- UninitializeConnectionInfo(_connection);
- _connection = null;
- }
- if (_websockets != null)
- {
- UninitializeWebSocketManager(_websockets);
- _websockets = null;
- }
+ _features = default;
+ _request.Uninitialize();
+ _response.Uninitialize();
+ _connection?.Uninitialize();
+ _websockets?.Uninitialize();
}
private IItemsFeature ItemsFeature =>
@@ -115,17 +90,9 @@ public virtual void Uninitialize()
public override HttpResponse Response => _response;
- public override ConnectionInfo Connection => _connection ?? (_connection = InitializeConnectionInfo());
-
- ///
- /// This is obsolete and will be removed in a future version.
- /// The recommended alternative is to use Microsoft.AspNetCore.Authentication.AuthenticationHttpContextExtensions.
- /// See https://go.microsoft.com/fwlink/?linkid=845470.
- ///
- [Obsolete("This is obsolete and will be removed in a future version. The recommended alternative is to use Microsoft.AspNetCore.Authentication.AuthenticationHttpContextExtensions. See https://go.microsoft.com/fwlink/?linkid=845470.")]
- public override AuthenticationManager Authentication => _authenticationManager ?? (_authenticationManager = InitializeAuthenticationManager());
+ public override ConnectionInfo Connection => _connection ?? (_connection = new DefaultConnectionInfo(_features.Collection));
- public override WebSocketManager WebSockets => _websockets ?? (_websockets = InitializeWebSocketManager());
+ public override WebSocketManager WebSockets => _websockets ?? (_websockets = new DefaultWebSocketManager(_features.Collection));
public override ClaimsPrincipal User
@@ -186,30 +153,11 @@ public override ISession Session
}
-
public override void Abort()
{
LifetimeFeature.Abort();
}
-
- protected virtual HttpRequest InitializeHttpRequest() => new DefaultHttpRequest(this);
- protected virtual void UninitializeHttpRequest(HttpRequest instance) { }
-
- protected virtual HttpResponse InitializeHttpResponse() => new DefaultHttpResponse(this);
- protected virtual void UninitializeHttpResponse(HttpResponse instance) { }
-
- protected virtual ConnectionInfo InitializeConnectionInfo() => new DefaultConnectionInfo(Features);
- protected virtual void UninitializeConnectionInfo(ConnectionInfo instance) { }
-
- [Obsolete("This is obsolete and will be removed in a future version. See https://go.microsoft.com/fwlink/?linkid=845470.")]
- protected virtual AuthenticationManager InitializeAuthenticationManager() => new DefaultAuthenticationManager(this);
- [Obsolete("This is obsolete and will be removed in a future version. See https://go.microsoft.com/fwlink/?linkid=845470.")]
- protected virtual void UninitializeAuthenticationManager(AuthenticationManager instance) { }
-
- protected virtual WebSocketManager InitializeWebSocketManager() => new DefaultWebSocketManager(Features);
- protected virtual void UninitializeWebSocketManager(WebSocketManager instance) { }
-
struct FeatureInterfaces
{
public IItemsFeature Items;
diff --git a/src/Http/Http/src/HttpContextFactory.cs b/src/Http/Http/src/HttpContextFactory.cs
index 9d7f3a1ad187..68f55b797ec7 100644
--- a/src/Http/Http/src/HttpContextFactory.cs
+++ b/src/Http/Http/src/HttpContextFactory.cs
@@ -55,7 +55,7 @@ private static HttpContext CreateHttpContext(IFeatureCollection featureCollectio
return container.HttpContext;
}
- return new ReusableHttpContext(featureCollection);
+ return new DefaultHttpContext(featureCollection);
}
public void Dispose(HttpContext httpContext)
diff --git a/src/Http/Http/src/Internal/DefaultConnectionInfo.cs b/src/Http/Http/src/Internal/DefaultConnectionInfo.cs
index 6ae7f9fc383d..96a00355ec9f 100644
--- a/src/Http/Http/src/Internal/DefaultConnectionInfo.cs
+++ b/src/Http/Http/src/Internal/DefaultConnectionInfo.cs
@@ -10,7 +10,7 @@
namespace Microsoft.AspNetCore.Http.Internal
{
- public class DefaultConnectionInfo : ConnectionInfo
+ public sealed class DefaultConnectionInfo : ConnectionInfo
{
// Lambdas hoisted to static readonly fields to improve inlining https://github.com/dotnet/roslyn/issues/13624
private readonly static Func _newHttpConnectionFeature = f => new HttpConnectionFeature();
@@ -23,14 +23,14 @@ public DefaultConnectionInfo(IFeatureCollection features)
Initialize(features);
}
- public virtual void Initialize( IFeatureCollection features)
+ public void Initialize( IFeatureCollection features)
{
_features = new FeatureReferences(features);
}
- public virtual void Uninitialize()
+ public void Uninitialize()
{
- _features = default(FeatureReferences);
+ _features = default;
}
private IHttpConnectionFeature HttpConnectionFeature =>
@@ -76,7 +76,7 @@ public override X509Certificate2 ClientCertificate
set { TlsConnectionFeature.ClientCertificate = value; }
}
- public override Task GetClientCertificateAsync(CancellationToken cancellationToken = new CancellationToken())
+ public override Task GetClientCertificateAsync(CancellationToken cancellationToken = default)
{
return TlsConnectionFeature.GetClientCertificateAsync(cancellationToken);
}
diff --git a/src/Http/Http/src/Internal/DefaultHttpRequest.cs b/src/Http/Http/src/Internal/DefaultHttpRequest.cs
index 4803942b9351..cd052d875e46 100644
--- a/src/Http/Http/src/Internal/DefaultHttpRequest.cs
+++ b/src/Http/Http/src/Internal/DefaultHttpRequest.cs
@@ -12,7 +12,7 @@
namespace Microsoft.AspNetCore.Http.Internal
{
- public class DefaultHttpRequest : HttpRequest
+ public sealed class DefaultHttpRequest : HttpRequest
{
// Lambdas hoisted to static readonly fields to improve inlining https://github.com/dotnet/roslyn/issues/13624
private readonly static Func _nullRequestFeature = f => null;
@@ -22,24 +22,23 @@ public class DefaultHttpRequest : HttpRequest
private readonly static Func _newRouteValuesFeature = f => new RouteValuesFeature();
private readonly static Func _newRequestBodyPipeFeature = context => new RequestBodyPipeFeature(context);
- private HttpContext _context;
+ private readonly DefaultHttpContext _context;
private FeatureReferences _features;
- public DefaultHttpRequest(HttpContext context)
+ public DefaultHttpRequest(DefaultHttpContext context)
{
- Initialize(context);
+ _context = context;
+ _features = new FeatureReferences(_context.Features);
}
- public virtual void Initialize(HttpContext context)
+ public void Initialize()
{
- _context = context;
- _features = new FeatureReferences(context.Features);
+ _features = new FeatureReferences(_context.Features);
}
- public virtual void Uninitialize()
+ public void Uninitialize()
{
- _context = null;
- _features = default(FeatureReferences);
+ _features = default;
}
public override HttpContext HttpContext => _context;
diff --git a/src/Http/Http/src/Internal/DefaultHttpResponse.cs b/src/Http/Http/src/Internal/DefaultHttpResponse.cs
index b7ac14c25ae2..0922da92f89c 100644
--- a/src/Http/Http/src/Internal/DefaultHttpResponse.cs
+++ b/src/Http/Http/src/Internal/DefaultHttpResponse.cs
@@ -10,31 +10,30 @@
namespace Microsoft.AspNetCore.Http.Internal
{
- public class DefaultHttpResponse : HttpResponse
+ public sealed class DefaultHttpResponse : HttpResponse
{
// Lambdas hoisted to static readonly fields to improve inlining https://github.com/dotnet/roslyn/issues/13624
private readonly static Func _nullResponseFeature = f => null;
private readonly static Func _newResponseCookiesFeature = f => new ResponseCookiesFeature(f);
private readonly static Func _newResponseBodyPipeFeature = context => new ResponseBodyPipeFeature(context);
- private HttpContext _context;
+ private readonly DefaultHttpContext _context;
private FeatureReferences _features;
- public DefaultHttpResponse(HttpContext context)
+ public DefaultHttpResponse(DefaultHttpContext context)
{
- Initialize(context);
+ _context = context;
+ _features = new FeatureReferences(_context.Features);
}
- public virtual void Initialize(HttpContext context)
+ public void Initialize()
{
- _context = context;
- _features = new FeatureReferences(context.Features);
+ _features = new FeatureReferences(_context.Features);
}
- public virtual void Uninitialize()
+ public void Uninitialize()
{
- _context = null;
- _features = default(FeatureReferences);
+ _features = default;
}
private IHttpResponseFeature HttpResponseFeature =>
diff --git a/src/Http/Http/src/Internal/DefaultWebSocketManager.cs b/src/Http/Http/src/Internal/DefaultWebSocketManager.cs
index 477282408d7c..e704d552e67b 100644
--- a/src/Http/Http/src/Internal/DefaultWebSocketManager.cs
+++ b/src/Http/Http/src/Internal/DefaultWebSocketManager.cs
@@ -10,7 +10,7 @@
namespace Microsoft.AspNetCore.Http.Internal
{
- public class DefaultWebSocketManager : WebSocketManager
+ public sealed class DefaultWebSocketManager : WebSocketManager
{
// Lambdas hoisted to static readonly fields to improve inlining https://github.com/dotnet/roslyn/issues/13624
private readonly static Func _nullRequestFeature = f => null;
@@ -23,14 +23,14 @@ public DefaultWebSocketManager(IFeatureCollection features)
Initialize(features);
}
- public virtual void Initialize(IFeatureCollection features)
+ public void Initialize(IFeatureCollection features)
{
_features = new FeatureReferences(features);
}
- public virtual void Uninitialize()
+ public void Uninitialize()
{
- _features = default(FeatureReferences);
+ _features = default;
}
private IHttpRequestFeature HttpRequestFeature =>
diff --git a/src/Http/Http/src/Internal/ReusableConnectionInfo.cs b/src/Http/Http/src/Internal/ReusableConnectionInfo.cs
deleted file mode 100644
index 9891ee6cbc80..000000000000
--- a/src/Http/Http/src/Internal/ReusableConnectionInfo.cs
+++ /dev/null
@@ -1,89 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Net;
-using System.Security.Cryptography.X509Certificates;
-using System.Text;
-using System.Threading;
-using System.Threading.Tasks;
-using Microsoft.AspNetCore.Http.Features;
-
-namespace Microsoft.AspNetCore.Http.Internal
-{
- public sealed class ReusableConnectionInfo : ConnectionInfo
- {
- // Lambdas hoisted to static readonly fields to improve inlining https://github.com/dotnet/roslyn/issues/13624
- private readonly static Func _newHttpConnectionFeature = f => new HttpConnectionFeature();
- private readonly static Func _newTlsConnectionFeature = f => new TlsConnectionFeature();
-
- private FeatureReferences _features;
-
- public ReusableConnectionInfo(IFeatureCollection features)
- {
- Initialize(features);
- }
-
- public void Initialize(IFeatureCollection features)
- {
- _features = new FeatureReferences(features);
- }
-
- public void Uninitialize()
- {
- _features = default(FeatureReferences);
- }
-
- private IHttpConnectionFeature HttpConnectionFeature =>
- _features.Fetch(ref _features.Cache.Connection, _newHttpConnectionFeature);
-
- private ITlsConnectionFeature TlsConnectionFeature =>
- _features.Fetch(ref _features.Cache.TlsConnection, _newTlsConnectionFeature);
-
- ///
- public override string Id
- {
- get { return HttpConnectionFeature.ConnectionId; }
- set { HttpConnectionFeature.ConnectionId = value; }
- }
-
- public override IPAddress RemoteIpAddress
- {
- get { return HttpConnectionFeature.RemoteIpAddress; }
- set { HttpConnectionFeature.RemoteIpAddress = value; }
- }
-
- public override int RemotePort
- {
- get { return HttpConnectionFeature.RemotePort; }
- set { HttpConnectionFeature.RemotePort = value; }
- }
-
- public override IPAddress LocalIpAddress
- {
- get { return HttpConnectionFeature.LocalIpAddress; }
- set { HttpConnectionFeature.LocalIpAddress = value; }
- }
-
- public override int LocalPort
- {
- get { return HttpConnectionFeature.LocalPort; }
- set { HttpConnectionFeature.LocalPort = value; }
- }
-
- public override X509Certificate2 ClientCertificate
- {
- get { return TlsConnectionFeature.ClientCertificate; }
- set { TlsConnectionFeature.ClientCertificate = value; }
- }
-
- public override Task GetClientCertificateAsync(CancellationToken cancellationToken = default)
- {
- return TlsConnectionFeature.GetClientCertificateAsync(cancellationToken);
- }
-
- struct FeatureInterfaces
- {
- public IHttpConnectionFeature Connection;
- public ITlsConnectionFeature TlsConnection;
- }
- }
-}
diff --git a/src/Http/Http/src/Internal/ReusableHttpContext.cs b/src/Http/Http/src/Internal/ReusableHttpContext.cs
deleted file mode 100644
index 29a7d7f9077c..000000000000
--- a/src/Http/Http/src/Internal/ReusableHttpContext.cs
+++ /dev/null
@@ -1,165 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Security.Claims;
-using System.Text;
-using System.Threading;
-using Microsoft.AspNetCore.Http.Authentication;
-using Microsoft.AspNetCore.Http.Features;
-using Microsoft.AspNetCore.Http.Features.Authentication;
-
-namespace Microsoft.AspNetCore.Http.Internal
-{
- public sealed class ReusableHttpContext : HttpContext
- {
- // Lambdas hoisted to static readonly fields to improve inlining https://github.com/dotnet/roslyn/issues/13624
- private readonly static Func _newItemsFeature = f => new ItemsFeature();
- private readonly static Func _newServiceProvidersFeature = f => new ServiceProvidersFeature();
- private readonly static Func _newHttpAuthenticationFeature = f => new HttpAuthenticationFeature();
- private readonly static Func _newHttpRequestLifetimeFeature = f => new HttpRequestLifetimeFeature();
- private readonly static Func _newSessionFeature = f => new DefaultSessionFeature();
- private readonly static Func _nullSessionFeature = f => null;
- private readonly static Func _newHttpRequestIdentifierFeature = f => new HttpRequestIdentifierFeature();
-
- private FeatureReferences _features;
-
- private ReusableHttpRequest _request;
- private ReusableHttpResponse _response;
-
- private ReusableConnectionInfo _connection;
- private ReusableWebSocketManager _websockets;
-
- public ReusableHttpContext(IFeatureCollection features)
- {
- _features = new FeatureReferences(features);
- _request = new ReusableHttpRequest(this);
- _response = new ReusableHttpResponse(this);
- }
-
- public void Initialize(IFeatureCollection features)
- {
- _features = new FeatureReferences(features);
- _request.Initialize(this);
- _response.Initialize(this);
- _connection?.Initialize(features);
- _websockets?.Initialize(features);
- }
-
- public void Uninitialize()
- {
- _features = default;
-
- _request.Uninitialize();
- _response.Uninitialize();
- _connection?.Uninitialize();
- _websockets?.Uninitialize();
- }
-
- private IItemsFeature ItemsFeature =>
- _features.Fetch(ref _features.Cache.Items, _newItemsFeature);
-
- private IServiceProvidersFeature ServiceProvidersFeature =>
- _features.Fetch(ref _features.Cache.ServiceProviders, _newServiceProvidersFeature);
-
- private IHttpAuthenticationFeature HttpAuthenticationFeature =>
- _features.Fetch(ref _features.Cache.Authentication, _newHttpAuthenticationFeature);
-
- private IHttpRequestLifetimeFeature LifetimeFeature =>
- _features.Fetch(ref _features.Cache.Lifetime, _newHttpRequestLifetimeFeature);
-
- private ISessionFeature SessionFeature =>
- _features.Fetch(ref _features.Cache.Session, _newSessionFeature);
-
- private ISessionFeature SessionFeatureOrNull =>
- _features.Fetch(ref _features.Cache.Session, _nullSessionFeature);
-
-
- private IHttpRequestIdentifierFeature RequestIdentifierFeature =>
- _features.Fetch(ref _features.Cache.RequestIdentifier, _newHttpRequestIdentifierFeature);
-
- public override IFeatureCollection Features => _features.Collection;
-
- public override HttpRequest Request => _request;
-
- public override HttpResponse Response => _response;
-
- public override ConnectionInfo Connection => _connection ?? (_connection = new ReusableConnectionInfo(_features.Collection));
-
- [Obsolete("This is obsolete and will be removed in a future version. The recommended alternative is to use Microsoft.AspNetCore.Authentication.AuthenticationHttpContextExtensions. See https://go.microsoft.com/fwlink/?linkid=845470.")]
- public override AuthenticationManager Authentication => throw new NotSupportedException();
-
- public override WebSocketManager WebSockets => _websockets ?? (_websockets = new ReusableWebSocketManager(_features.Collection));
-
-
- public override ClaimsPrincipal User
- {
- get
- {
- var user = HttpAuthenticationFeature.User;
- if (user == null)
- {
- user = new ClaimsPrincipal(new ClaimsIdentity());
- HttpAuthenticationFeature.User = user;
- }
- return user;
- }
- set { HttpAuthenticationFeature.User = value; }
- }
-
- public override IDictionary