Skip to content

seal DefaultHttpContext and remove obsolete members #6504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions src/Http/Http.Abstractions/src/HttpContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,6 @@ public abstract class HttpContext
/// </summary>
public abstract WebSocketManager WebSockets { get; }

/// <summary>
/// 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.
/// </summary>
[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; }

/// <summary>
/// Gets or sets the user for this request.
/// </summary>
Expand Down
184 changes: 0 additions & 184 deletions src/Http/Http/src/Authentication/DefaultAuthenticationManager.cs

This file was deleted.

94 changes: 21 additions & 73 deletions src/Http/Http/src/DefaultHttpContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IFeatureCollection, IItemsFeature> _newItemsFeature = f => new ItemsFeature();
Expand All @@ -26,15 +24,11 @@ public class DefaultHttpContext : HttpContext

private FeatureReferences<FeatureInterfaces> _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())
Expand All @@ -45,46 +39,27 @@ public DefaultHttpContext()

public DefaultHttpContext(IFeatureCollection features)
{
Initialize(features);
_features = new FeatureReferences<FeatureInterfaces>(features);
_request = new DefaultHttpRequest(this);
_response = new DefaultHttpResponse(this);
}

public virtual void Initialize(IFeatureCollection features)
public void Initialize(IFeatureCollection features)
{
_features = new FeatureReferences<FeatureInterfaces>(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<FeatureInterfaces>);
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 =>
Expand Down Expand Up @@ -115,17 +90,9 @@ public virtual void Uninitialize()

public override HttpResponse Response => _response;

public override ConnectionInfo Connection => _connection ?? (_connection = InitializeConnectionInfo());

/// <summary>
/// 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.
/// </summary>
[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
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Http/src/HttpContextFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions src/Http/Http/src/Internal/DefaultConnectionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IFeatureCollection, IHttpConnectionFeature> _newHttpConnectionFeature = f => new HttpConnectionFeature();
Expand All @@ -23,14 +23,14 @@ public DefaultConnectionInfo(IFeatureCollection features)
Initialize(features);
}

public virtual void Initialize( IFeatureCollection features)
public void Initialize( IFeatureCollection features)
{
_features = new FeatureReferences<FeatureInterfaces>(features);
}

public virtual void Uninitialize()
public void Uninitialize()
{
_features = default(FeatureReferences<FeatureInterfaces>);
_features = default;
}

private IHttpConnectionFeature HttpConnectionFeature =>
Expand Down Expand Up @@ -76,7 +76,7 @@ public override X509Certificate2 ClientCertificate
set { TlsConnectionFeature.ClientCertificate = value; }
}

public override Task<X509Certificate2> GetClientCertificateAsync(CancellationToken cancellationToken = new CancellationToken())
public override Task<X509Certificate2> GetClientCertificateAsync(CancellationToken cancellationToken = default)
{
return TlsConnectionFeature.GetClientCertificateAsync(cancellationToken);
}
Expand Down
Loading