Skip to content

Commit f1b1e19

Browse files
committed
PR feedback and fixes
1 parent e3ed98e commit f1b1e19

File tree

4 files changed

+49
-49
lines changed

4 files changed

+49
-49
lines changed

src/Servers/HttpSys/HttpSysServer.slnf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"src\\Servers\\HttpSys\\src\\Microsoft.AspNetCore.Server.HttpSys.csproj",
2424
"src\\Servers\\HttpSys\\test\\FunctionalTests\\Microsoft.AspNetCore.Server.HttpSys.FunctionalTests.csproj",
2525
"src\\Servers\\HttpSys\\test\\Tests\\Microsoft.AspNetCore.Server.HttpSys.Tests.csproj",
26-
"src\\Servers\\Kestrel\\Transport.Sockets\\src\\Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj"
26+
"src\\Servers\\Kestrel\\Transport.Sockets\\src\\Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj",
27+
"src\\Testing\\src\\Microsoft.AspNetCore.Testing.csproj"
2728
]
2829
}
2930
}

src/Servers/HttpSys/src/AsyncAcceptContext.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,16 @@ private static void IOCompleted(AsyncAcceptContext asyncContext, uint errorCode,
7474

7575
if (server.ValidateRequest(requestContext) && server.ValidateAuth(requestContext))
7676
{
77-
// It's important that we clear the native request context before we set the result
78-
// we want to reuse this object for future accepts.
77+
// It's important that we clear the request context before we set the result
78+
// we want to reuse the acceptContext object for future accepts.
7979
asyncContext._requestContext = null;
8080

81-
requestContext.Initialize();
81+
// Initialize features here once we're successfully validated the request
82+
// TODO: In the future defer this work to the thread pool so we can get off the IO thread
83+
// as quickly as possible
84+
requestContext.InitializeFeatures();
8285

83-
asyncContext._tcs.SetResult(requestContext);
86+
asyncContext._mrvts.SetResult(requestContext);
8487

8588
complete = true;
8689
}
@@ -199,11 +202,11 @@ protected virtual void Dispose(bool disposing)
199202
{
200203
if (disposing)
201204
{
202-
if (_nativeRequestContext != null)
205+
if (_requestContext != null)
203206
{
204-
_nativeRequestContext.ReleasePins();
205-
_nativeRequestContext.Dispose();
206-
_nativeRequestContext = null;
207+
_requestContext.ReleasePins();
208+
_requestContext.Dispose();
209+
_requestContext = null;
207210

208211
var boundHandle = Server.RequestQueue.BoundHandle;
209212

src/Servers/HttpSys/src/RequestProcessing/RequestContext.FeatureCollection.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,40 @@ private enum Fields
9393
TraceIdentifier = 0x200,
9494
}
9595

96+
public void InitializeFeatures()
97+
{
98+
if (_initialized)
99+
{
100+
return;
101+
}
102+
103+
_initialized = true;
104+
105+
Request = new Request(this);
106+
Response = new Response(this);
107+
108+
_features = new FeatureCollection(new StandardFeatureCollection(this));
109+
_enableResponseCaching = Server.Options.EnableResponseCaching;
110+
111+
// Pre-initialize any fields that are not lazy at the lower level.
112+
_requestHeaders = Request.Headers;
113+
_httpMethod = Request.Method;
114+
_path = Request.Path;
115+
_pathBase = Request.PathBase;
116+
_query = Request.QueryString;
117+
_rawTarget = Request.RawUrl;
118+
_scheme = Request.Scheme;
119+
120+
if (Server.Options.Authentication.AutomaticAuthentication)
121+
{
122+
_user = User;
123+
}
124+
125+
_responseStream = new ResponseStream(Response.Body, OnResponseStart);
126+
_responseHeaders = Response.Headers;
127+
}
128+
129+
96130
private bool IsNotInitialized(Fields field)
97131
{
98132
return (_initializedFields & field) != field;

src/Servers/HttpSys/src/RequestProcessing/RequestContext.cs

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5-
using System.Collections.Concurrent;
65
using System.Diagnostics;
76
using System.IO;
8-
using System.Runtime.InteropServices;
97
using System.Security.Authentication.ExtendedProtection;
108
using System.Security.Principal;
119
using System.Threading;
1210
using System.Threading.Tasks;
1311
using Microsoft.AspNetCore.Http;
14-
using Microsoft.AspNetCore.Http.Features;
1512
using Microsoft.AspNetCore.HttpSys.Internal;
1613
using Microsoft.Extensions.Logging;
1714

@@ -38,9 +35,9 @@ public RequestContext(HttpSysListener server, uint? bufferSize, ulong requestId)
3835

3936
internal ILogger Logger => Server.Logger;
4037

41-
public Request Request { get; set; }
38+
public Request Request { get; private set; }
4239

43-
public Response Response { get; set; }
40+
public Response Response { get; private set; }
4441

4542
public WindowsPrincipal User => Request.User;
4643

@@ -251,8 +248,6 @@ public async void Execute()
251248
var messagePump = MessagePump;
252249
var application = messagePump.Application;
253250

254-
Initialize();
255-
256251
try
257252
{
258253
if (messagePump.Stopping)
@@ -323,39 +318,6 @@ public async void Execute()
323318
}
324319
}
325320

326-
public void Initialize()
327-
{
328-
if (_initialized)
329-
{
330-
return;
331-
}
332-
333-
_initialized = true;
334-
335-
Request = new Request(this);
336-
Response = new Response(this);
337-
338-
_features = new FeatureCollection(new StandardFeatureCollection(this));
339-
_enableResponseCaching = Server.Options.EnableResponseCaching;
340-
341-
// Pre-initialize any fields that are not lazy at the lower level.
342-
_requestHeaders = Request.Headers;
343-
_httpMethod = Request.Method;
344-
_path = Request.Path;
345-
_pathBase = Request.PathBase;
346-
_query = Request.QueryString;
347-
_rawTarget = Request.RawUrl;
348-
_scheme = Request.Scheme;
349-
350-
if (Server.Options.Authentication.AutomaticAuthentication)
351-
{
352-
_user = User;
353-
}
354-
355-
_responseStream = new ResponseStream(Response.Body, OnResponseStart);
356-
_responseHeaders = Response.Headers;
357-
}
358-
359321
private void SetFatalResponse(int status)
360322
{
361323
Response.StatusCode = status;

0 commit comments

Comments
 (0)