Skip to content

Commit de3fa99

Browse files
committed
Avoid branches and other PR feedback
1 parent 179c445 commit de3fa99

File tree

3 files changed

+13
-42
lines changed

3 files changed

+13
-42
lines changed

src/Http/Http/src/HttpContextFactory.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using Microsoft.AspNetCore.Http.Features;
6+
using Microsoft.AspNetCore.Http.Internal;
67
using Microsoft.Extensions.Options;
78

89
namespace Microsoft.AspNetCore.Http
@@ -49,7 +50,7 @@ public HttpContext Create(IFeatureCollection featureCollection)
4950

5051
protected virtual HttpContext CreateHttpContext(IFeatureCollection featureCollection)
5152
{
52-
return new DefaultHttpContext(featureCollection);
53+
return new ReusableHttpContext(featureCollection);
5354
}
5455

5556
public void Dispose(HttpContext httpContext)

src/Http/Http/src/Internal/ReusableHttpContext.cs

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -30,49 +30,26 @@ public sealed class ReusableHttpContext : HttpContext
3030

3131
public ReusableHttpContext(IFeatureCollection features)
3232
{
33-
Initialize(features);
33+
_features = new FeatureReferences<FeatureInterfaces>(features);
34+
_request = new ReusableHttpRequest(this);
35+
_response = new ReusableHttpResponse(this);
3436
}
3537

3638
public void Initialize(IFeatureCollection features)
3739
{
3840
_features = new FeatureReferences<FeatureInterfaces>(features);
39-
40-
if (_request is null)
41-
{
42-
_request = new ReusableHttpRequest(this);
43-
}
44-
else
45-
{
46-
_request.Initialize(this);
47-
}
48-
49-
if (_response is null)
50-
{
51-
_response = new ReusableHttpResponse(this);
52-
}
53-
else
54-
{
55-
_response.Initialize(this);
56-
}
57-
58-
// Only set the ConnectionInfo if it was already allocated
59-
if (_connection != null)
60-
{
61-
_connection.Initialize(features);
62-
}
63-
64-
if (_websockets != null)
65-
{
66-
_websockets.Initialize(features);
67-
}
41+
_request.Initialize(this);
42+
_response.Initialize(this);
43+
_connection?.Initialize(features);
44+
_websockets?.Initialize(features);
6845
}
6946

7047
public void Uninitialize()
7148
{
7249
_features = default;
7350

74-
_request?.Uninitialize();
75-
_response?.Uninitialize();
51+
_request.Uninitialize();
52+
_response.Uninitialize();
7653
_connection?.Uninitialize();
7754
_websockets?.Uninitialize();
7855
}
@@ -106,12 +83,7 @@ public void Uninitialize()
10683
public override HttpResponse Response => _response;
10784

10885
public override ConnectionInfo Connection => _connection ?? (_connection = new ReusableConnectionInfo(_features.Collection));
109-
110-
/// <summary>
111-
/// This is obsolete and will be removed in a future version.
112-
/// The recommended alternative is to use Microsoft.AspNetCore.Authentication.AuthenticationHttpContextExtensions.
113-
/// See https://go.microsoft.com/fwlink/?linkid=845470.
114-
/// </summary>
86+
11587
[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.")]
11688
public override AuthenticationManager Authentication => throw new NotSupportedException();
11789

@@ -175,8 +147,6 @@ public override ISession Session
175147
}
176148
}
177149

178-
179-
180150
public override void Abort()
181151
{
182152
LifetimeFeature.Abort();

src/Servers/Kestrel/Core/src/Internal/Http/HttpProtocol.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ public CancellationToken RequestAborted
277277

278278
protected HttpResponseHeaders HttpResponseHeaders { get; } = new HttpResponseHeaders();
279279

280-
internal HttpContext HttpContext => _httpContext;
280+
internal ReusableHttpContext HttpContext => _httpContext;
281281

282282
public void InitializeStreams(MessageBody messageBody)
283283
{

0 commit comments

Comments
 (0)