Skip to content

Commit 8526622

Browse files
committed
Move all of it into HttpProtocol
1 parent 56cac8f commit 8526622

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public abstract partial class HttpProtocol : IHttpResponseControl
6363
private long _responseBytesWritten;
6464

6565
private readonly HttpConnectionContext _context;
66+
private DefaultHttpContext _httpContext;
6667

6768
protected string _methodText = null;
6869
private string _scheme = null;
@@ -98,9 +99,6 @@ public HttpProtocol(HttpConnectionContext context)
9899
public long? MaxRequestBodySize { get; set; }
99100
public bool AllowSynchronousIO { get; set; }
100101

101-
// Caches the HttpContext allocation
102-
internal DefaultHttpContext HttpContext { get; set; }
103-
104102
/// <summary>
105103
/// The request id. <seealso cref="HttpContext.TraceIdentifier"/>
106104
/// </summary>
@@ -278,6 +276,20 @@ public CancellationToken RequestAborted
278276

279277
protected HttpResponseHeaders HttpResponseHeaders { get; } = new HttpResponseHeaders();
280278

279+
internal HttpContext InitializeHttpContext()
280+
{
281+
if (_httpContext is null)
282+
{
283+
_httpContext = new DefaultHttpContext(this);
284+
}
285+
else
286+
{
287+
_httpContext.Initialize(this);
288+
}
289+
290+
return _httpContext;
291+
}
292+
281293
public void InitializeStreams(MessageBody messageBody)
282294
{
283295
if (_streams == null)
@@ -362,7 +374,7 @@ public void Reset()
362374

363375
_responseBytesWritten = 0;
364376

365-
HttpContext?.Uninitialize();
377+
_httpContext?.Uninitialize();
366378

367379
OnReset();
368380
}

src/Servers/Kestrel/Core/src/Internal/KestrelHttpContextFactory.cs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,7 @@ protected override HttpContext CreateHttpContext(IFeatureCollection featureColle
2424
{
2525
if (featureCollection is HttpProtocol protocol)
2626
{
27-
// First request, the HttpContext is null, so make a new one
28-
if (protocol.HttpContext == null)
29-
{
30-
protocol.HttpContext = new DefaultHttpContext(featureCollection);
31-
}
32-
else
33-
{
34-
// Otherwise just initialize the feature collection on the existing connection
35-
protocol.HttpContext.Initialize(featureCollection);
36-
}
37-
38-
return protocol.HttpContext;
27+
return protocol.InitializeHttpContext();
3928
}
4029

4130
// Since Kestrel is registered by default, we need to fallback to the default behavior

0 commit comments

Comments
 (0)