Skip to content
This repository was archived by the owner on Mar 19, 2019. It is now read-only.

Commit d7ce8d8

Browse files
committed
#283 Update naming, merge options
1 parent 4c388e8 commit d7ce8d8

32 files changed

+152
-212
lines changed

samples/HotAddSample/Startup.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ public class Startup
1515
{
1616
public void ConfigureServices(IServiceCollection services)
1717
{
18-
services.Configure<WebListenerOptions>(options =>
18+
services.Configure<HttpSysOptions>(options =>
1919
{
20-
ListenerSettings = options.ListenerSettings;
20+
ServerOptions = options;
2121
});
2222
}
2323

24-
public WebListenerSettings ListenerSettings { get; set; }
24+
public HttpSysOptions ServerOptions { get; set; }
2525

2626
public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory)
2727
{
2828
loggerfactory.AddConsole(LogLevel.Information);
2929

30-
var addresses = ListenerSettings.UrlPrefixes;
30+
var addresses = ServerOptions.UrlPrefixes;
3131
addresses.Add("http://localhost:12346/pathBase/");
3232

3333
app.Use(async (context, next) =>
@@ -102,7 +102,7 @@ public static void Main(string[] args)
102102
{
103103
var host = new WebHostBuilder()
104104
.UseStartup<Startup>()
105-
.UseWebListener()
105+
.UseHttpSys()
106106
.Build();
107107

108108
host.Run();

samples/SelfHostServer/Startup.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ public class Startup
1616
public void ConfigureServices(IServiceCollection services)
1717
{
1818
// Server options can be configured here instead of in Main.
19-
services.Configure<WebListenerOptions>(options =>
19+
services.Configure<HttpSysOptions>(options =>
2020
{
21-
options.ListenerSettings.Authentication.Schemes = AuthenticationSchemes.None;
22-
options.ListenerSettings.Authentication.AllowAnonymous = true;
21+
options.Authentication.Schemes = AuthenticationSchemes.None;
22+
options.Authentication.AllowAnonymous = true;
2323
});
2424
}
2525

@@ -49,10 +49,10 @@ public static void Main(string[] args)
4949
{
5050
var host = new WebHostBuilder()
5151
.UseStartup<Startup>()
52-
.UseWebListener(options =>
52+
.UseHttpSys(options =>
5353
{
54-
options.ListenerSettings.Authentication.Schemes = AuthenticationSchemes.None;
55-
options.ListenerSettings.Authentication.AllowAnonymous = true;
54+
options.Authentication.Schemes = AuthenticationSchemes.None;
55+
options.Authentication.AllowAnonymous = true;
5656
})
5757
.Build();
5858

src/Microsoft.AspNetCore.Server.HttpSys/AsyncAcceptContext.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ internal unsafe class AsyncAcceptContext : IAsyncResult, IDisposable
1414
internal static readonly IOCompletionCallback IOCallback = new IOCompletionCallback(IOWaitCallback);
1515

1616
private TaskCompletionSource<RequestContext> _tcs;
17-
private WebListener _server;
17+
private HttpSysListener _server;
1818
private NativeRequestContext _nativeRequestContext;
1919

20-
internal AsyncAcceptContext(WebListener server)
20+
internal AsyncAcceptContext(HttpSysListener server)
2121
{
2222
_server = server;
2323
_tcs = new TaskCompletionSource<RequestContext>();
@@ -40,7 +40,7 @@ private TaskCompletionSource<RequestContext> Tcs
4040
}
4141
}
4242

43-
internal WebListener Server
43+
internal HttpSysListener Server
4444
{
4545
get
4646
{
@@ -58,12 +58,12 @@ private static void IOCompleted(AsyncAcceptContext asyncResult, uint errorCode,
5858
if (errorCode != UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS &&
5959
errorCode != UnsafeNclNativeMethods.ErrorCodes.ERROR_MORE_DATA)
6060
{
61-
asyncResult.Tcs.TrySetException(new WebListenerException((int)errorCode));
61+
asyncResult.Tcs.TrySetException(new HttpSysException((int)errorCode));
6262
complete = true;
6363
}
6464
else
6565
{
66-
WebListener server = asyncResult.Server;
66+
HttpSysListener server = asyncResult.Server;
6767
if (errorCode == UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS)
6868
{
6969
// at this point we have received an unmanaged HTTP_REQUEST and memoryBlob
@@ -106,7 +106,7 @@ private static void IOCompleted(AsyncAcceptContext asyncResult, uint errorCode,
106106
{
107107
// someother bad error, possible(?) return values are:
108108
// ERROR_INVALID_HANDLE, ERROR_INSUFFICIENT_BUFFER, ERROR_OPERATION_ABORTED
109-
asyncResult.Tcs.TrySetException(new WebListenerException((int)statusCode));
109+
asyncResult.Tcs.TrySetException(new HttpSysException((int)statusCode));
110110
complete = true;
111111
}
112112
}
@@ -169,7 +169,7 @@ internal uint QueueBeginGetContext()
169169
retry = true;
170170
}
171171
else if (statusCode == UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS
172-
&& WebListener.SkipIOCPCallbackOnSuccess)
172+
&& HttpSysListener.SkipIOCPCallbackOnSuccess)
173173
{
174174
// IO operation completed synchronously - callback won't be called to signal completion.
175175
IOCompleted(this, statusCode, bytesTransferred);

src/Microsoft.AspNetCore.Server.HttpSys/WebListenerException.cs renamed to src/Microsoft.AspNetCore.Server.HttpSys/HttpSysException.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@
99
namespace Microsoft.AspNetCore.Server.HttpSys
1010
{
1111
[SuppressMessage("Microsoft.Usage", "CA2237:MarkISerializableTypesWithSerializable")]
12-
public class WebListenerException : Win32Exception
12+
public class HttpSysException : Win32Exception
1313
{
14-
internal WebListenerException()
14+
internal HttpSysException()
1515
: base(Marshal.GetLastWin32Error())
1616
{
1717
}
1818

19-
internal WebListenerException(int errorCode)
19+
internal HttpSysException(int errorCode)
2020
: base(errorCode)
2121
{
2222
}
2323

24-
internal WebListenerException(int errorCode, string message)
24+
internal HttpSysException(int errorCode, string message)
2525
: base(errorCode, message)
2626
{
2727
}

src/Microsoft.AspNetCore.Server.HttpSys/WebListener.cs renamed to src/Microsoft.AspNetCore.Server.HttpSys/HttpSysListener.cs

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
1414
/// <summary>
1515
/// An HTTP server wrapping the Http.Sys APIs that accepts requests.
1616
/// </summary>
17-
public sealed class WebListener : IDisposable
17+
public sealed class HttpSysListener : IDisposable
1818
{
1919
// Win8# 559317 fixed a bug in Http.sys's HttpReceiveClientCertificate method.
2020
// Without this fix IOCP callbacks were not being called although ERROR_IO_PENDING was
@@ -40,16 +40,15 @@ public sealed class WebListener : IDisposable
4040

4141
private object _internalLock;
4242

43-
public WebListener()
44-
: this(new WebListenerSettings())
43+
public HttpSysListener(HttpSysOptions options, ILoggerFactory loggerFactory)
4544
{
46-
}
47-
48-
public WebListener(WebListenerSettings settings)
49-
{
50-
if (settings == null)
45+
if (options == null)
46+
{
47+
throw new ArgumentNullException(nameof(options));
48+
}
49+
if (loggerFactory == null)
5150
{
52-
throw new ArgumentNullException(nameof(settings));
51+
throw new ArgumentNullException(nameof(loggerFactory));
5352
}
5453

5554
if (!HttpApi.Supported)
@@ -59,7 +58,9 @@ public WebListener(WebListenerSettings settings)
5958

6059
Debug.Assert(HttpApi.ApiVersion == HttpApi.HTTP_API_VERSION.Version20, "Invalid Http api version");
6160

62-
Settings = settings;
61+
Options = options;
62+
63+
Logger = LogHelper.CreateLogger(loggerFactory, typeof(HttpSysListener));
6364

6465
_state = State.Stopped;
6566
_internalLock = new object();
@@ -99,10 +100,7 @@ internal enum State
99100
Disposed,
100101
}
101102

102-
internal ILogger Logger
103-
{
104-
get { return Settings.Logger; }
105-
}
103+
internal ILogger Logger { get; private set; }
106104

107105
internal UrlGroup UrlGroup
108106
{
@@ -119,7 +117,7 @@ internal DisconnectListener DisconnectListener
119117
get { return _disconnectListener; }
120118
}
121119

122-
public WebListenerSettings Settings { get; }
120+
public HttpSysOptions Options { get; }
123121

124122
public bool IsListening
125123
{
@@ -148,18 +146,18 @@ public void Start()
148146
return;
149147
}
150148

151-
Settings.Authentication.SetUrlGroupSecurity(UrlGroup);
152-
Settings.Timeouts.SetUrlGroupTimeouts(UrlGroup);
153-
Settings.SetRequestQueueLimit(RequestQueue);
149+
Options.Authentication.SetUrlGroupSecurity(UrlGroup);
150+
Options.Timeouts.SetUrlGroupTimeouts(UrlGroup);
151+
Options.SetRequestQueueLimit(RequestQueue);
154152

155153
_requestQueue.AttachToUrlGroup();
156154

157155
// All resources are set up correctly. Now add all prefixes.
158156
try
159157
{
160-
Settings.UrlPrefixes.RegisterAllPrefixes(UrlGroup);
158+
Options.UrlPrefixes.RegisterAllPrefixes(UrlGroup);
161159
}
162-
catch (WebListenerException)
160+
catch (HttpSysException)
163161
{
164162
// If an error occurred while adding prefixes, free all resources allocated by previous steps.
165163
_requestQueue.DetachFromUrlGroup();
@@ -191,7 +189,7 @@ private void Stop()
191189
return;
192190
}
193191

194-
Settings.UrlPrefixes.UnregisterAllPrefixes();
192+
Options.UrlPrefixes.UnregisterAllPrefixes();
195193

196194
_state = State.Stopped;
197195

@@ -285,7 +283,7 @@ public Task<RequestContext> AcceptAsync()
285283
// some other bad error, possible(?) return values are:
286284
// ERROR_INVALID_HANDLE, ERROR_INSUFFICIENT_BUFFER, ERROR_OPERATION_ABORTED
287285
asyncResult.Dispose();
288-
throw new WebListenerException((int)statusCode);
286+
throw new HttpSysException((int)statusCode);
289287
}
290288
}
291289
catch (Exception exception)
@@ -310,10 +308,10 @@ internal unsafe bool ValidateRequest(NativeRequestContext requestMemory)
310308

311309
internal unsafe bool ValidateAuth(NativeRequestContext requestMemory)
312310
{
313-
if (!Settings.Authentication.AllowAnonymous && !requestMemory.CheckAuthenticated())
311+
if (!Options.Authentication.AllowAnonymous && !requestMemory.CheckAuthenticated())
314312
{
315313
SendError(requestMemory.RequestId, StatusCodes.Status401Unauthorized,
316-
AuthenticationManager.GenerateChallenges(Settings.Authentication.Schemes));
314+
AuthenticationManager.GenerateChallenges(Options.Authentication.Schemes));
317315
return false;
318316
}
319317
return true;

src/Microsoft.AspNetCore.Server.HttpSys/WebListenerSettings.cs renamed to src/Microsoft.AspNetCore.Server.HttpSys/HttpSysOptions.cs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,31 @@
77

88
namespace Microsoft.AspNetCore.Server.HttpSys
99
{
10-
public class WebListenerSettings
10+
public class HttpSysOptions
1111
{
1212
private const long DefaultRequestQueueLength = 1000; // Http.sys default.
13+
internal static readonly int DefaultMaxAccepts = 5 * Environment.ProcessorCount;
1314

1415
// The native request queue
1516
private long _requestQueueLength = DefaultRequestQueueLength;
1617
private RequestQueue _requestQueue;
1718
private ILogger _logger = NullLogger.Instance;
1819

19-
public WebListenerSettings()
20+
public HttpSysOptions()
2021
{
2122
}
2223

2324
/// <summary>
24-
/// The logger that will be used to create the WebListener instance. This should not be changed
25-
/// after creating the listener.
25+
/// The maximum number of concurrent accepts.
2626
/// </summary>
27-
public ILogger Logger
28-
{
29-
get { return _logger; }
30-
set
31-
{
32-
if (value == null)
33-
{
34-
throw new ArgumentNullException(nameof(value));
35-
}
36-
_logger = value;
37-
}
38-
}
27+
public int MaxAccepts { get; set; } = DefaultMaxAccepts;
28+
29+
/// <summary>
30+
/// Attempts kernel mode caching for responses with eligible headers. The response may not include
31+
/// Set-Cookie, Vary, or Pragma headers. It must include a Cache-Control header with Public and
32+
/// either a Shared-Max-Age or Max-Age value, or an Expires header.
33+
/// </summary>
34+
public bool EnableResponseCaching { get; set; } = true;
3935

4036
/// <summary>
4137
/// The url prefixes to register with Http.Sys. These may be modified at any time prior to disposing

src/Microsoft.AspNetCore.Server.HttpSys/Internal/WebListenerOptionsSetup.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/Microsoft.AspNetCore.Server.HttpSys/MessagePump.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
1616
{
1717
internal class MessagePump : IServer
1818
{
19-
private readonly WebListener _listener;
19+
private readonly HttpSysListener _listener;
2020
private readonly ILogger _logger;
2121

2222
private IHttpApplication<object> _application;
@@ -31,7 +31,7 @@ internal class MessagePump : IServer
3131

3232
private readonly ServerAddressesFeature _serverAddresses;
3333

34-
public MessagePump(IOptions<WebListenerOptions> options, ILoggerFactory loggerFactory)
34+
public MessagePump(IOptions<HttpSysOptions> options, ILoggerFactory loggerFactory)
3535
{
3636
if (options == null)
3737
{
@@ -43,7 +43,7 @@ public MessagePump(IOptions<WebListenerOptions> options, ILoggerFactory loggerFa
4343
}
4444

4545
var optionsInstance = options.Value;
46-
_listener = new WebListener(optionsInstance.ListenerSettings);
46+
_listener = new HttpSysListener(optionsInstance, loggerFactory);
4747
_logger = LogHelper.CreateLogger(loggerFactory, typeof(MessagePump));
4848
Features = new FeatureCollection();
4949
_serverAddresses = new ServerAddressesFeature();
@@ -55,7 +55,7 @@ public MessagePump(IOptions<WebListenerOptions> options, ILoggerFactory loggerFa
5555
_shutdownSignal = new ManualResetEvent(false);
5656
}
5757

58-
internal WebListener Listener
58+
internal HttpSysListener Listener
5959
{
6060
get { return _listener; }
6161
}
@@ -80,7 +80,7 @@ public void Start<TContext>(IHttpApplication<TContext> application)
8080

8181
_application = new ApplicationWrapper<TContext>(application);
8282

83-
if (_listener.Settings.UrlPrefixes.Count == 0)
83+
if (_listener.Options.UrlPrefixes.Count == 0)
8484
{
8585
throw new InvalidOperationException("No address prefixes were defined.");
8686
}
@@ -206,11 +206,11 @@ private static void SetFatalResponse(RequestContext context, int status)
206206
context.Dispose();
207207
}
208208

209-
private void ParseAddresses(ICollection<string> addresses, WebListener listener)
209+
private void ParseAddresses(ICollection<string> addresses, HttpSysListener listener)
210210
{
211211
foreach (var value in addresses)
212212
{
213-
listener.Settings.UrlPrefixes.Add(UrlPrefix.Create(value));
213+
listener.Options.UrlPrefixes.Add(UrlPrefix.Create(value));
214214
}
215215
}
216216

0 commit comments

Comments
 (0)