public MessagePump(IOptions <HttpSysOptions> options, ILoggerFactory loggerFactory, IAuthenticationSchemeProvider authentication) { if (options == null) { throw new ArgumentNullException(nameof(options)); } if (loggerFactory == null) { throw new ArgumentNullException(nameof(loggerFactory)); } _options = options.Value; Listener = new HttpSysListener(_options, loggerFactory); _logger = loggerFactory.CreateLogger <MessagePump>(); if (_options.Authentication.Schemes != AuthenticationSchemes.None) { authentication.AddScheme(new AuthenticationScheme(HttpSysDefaults.AuthenticationScheme, displayName: _options.Authentication.AuthenticationDisplayName, handlerType: typeof(AuthenticationHandler))); } Features = new FeatureCollection(); _serverAddresses = new ServerAddressesFeature(); Features.Set <IServerAddressesFeature>(_serverAddresses); if (HttpApi.IsFeatureSupported(HttpApiTypes.HTTP_FEATURE_ID.HttpFeatureDelegateEx)) { var delegationProperty = new ServerDelegationPropertyFeature(Listener.RequestQueue, _logger); Features.Set <IServerDelegationFeature>(delegationProperty); } _maxAccepts = _options.MaxAccepts; }
public MessagePump(IOptions <HttpSysOptions> options, ILoggerFactory loggerFactory, IAuthenticationSchemeProvider authentication) { if (options == null) { throw new ArgumentNullException(nameof(options)); } if (loggerFactory == null) { throw new ArgumentNullException(nameof(loggerFactory)); } _options = options.Value; Listener = new HttpSysListener(_options, loggerFactory); _logger = loggerFactory.CreateLogger <MessagePump>(); if (_options.Authentication.Schemes != AuthenticationSchemes.None) { authentication.AddScheme(new AuthenticationScheme(HttpSysDefaults.AuthenticationScheme, displayName: null, handlerType: typeof(AuthenticationHandler))); } Features = new FeatureCollection(); _serverAddresses = new ServerAddressesFeature(); Features.Set <IServerAddressesFeature>(_serverAddresses); _maxAccepts = _options.MaxAccepts; }
public async Task Server_SetConnectionLimitChangeAfterStarted_Success() { HttpSysOptions options = null; using (Utilities.CreateDynamicHost(out var address, opt => { options = opt; Assert.Null(options.MaxConnections); options.MaxConnections = 3; }, httpContext => Task.FromResult(0))) { using (var client1 = await SendHungRequestAsync("GET", address)) using (var client2 = await SendHungRequestAsync("GET", address)) using (var client3 = await SendHungRequestAsync("GET", address)) { // Maxed out, refuses connection and throws await Assert.ThrowsAsync <HttpRequestException>(() => SendRequestAsync(address)); options.MaxConnections = 4; string responseText = await SendRequestAsync(address); Assert.Equal(string.Empty, responseText); options.MaxConnections = 2; // Maxed out, refuses connection and throws await Assert.ThrowsAsync <HttpRequestException>(() => SendRequestAsync(address)); } } }
internal static MessagePump CreatePump(Action <HttpSysOptions> configureOptions, ILoggerFactory loggerFactory = null) { var options = new HttpSysOptions(); configureOptions(options); return(new MessagePump(Options.Create(options), loggerFactory ?? new LoggerFactory(), new AuthenticationSchemeProvider(Options.Create(new AuthenticationOptions())))); }
public HttpSysListener(HttpSysOptions options, ILoggerFactory loggerFactory) { if (options == null) { throw new ArgumentNullException(nameof(options)); } if (loggerFactory == null) { throw new ArgumentNullException(nameof(loggerFactory)); } if (!HttpApi.Supported) { throw new PlatformNotSupportedException(); } Debug.Assert(HttpApi.ApiVersion == HttpApiTypes.HTTP_API_VERSION.Version20, "Invalid Http api version"); Options = options; Logger = loggerFactory.CreateLogger <HttpSysListener>(); _state = State.Stopped; _internalLock = new object(); // V2 initialization sequence: // 1. Create server session // 2. Create url group // 3. Create request queue // 4. Add urls to url group - Done in Start() // 5. Attach request queue to url group - Done in Start() try { _serverSession = new ServerSession(); _urlGroup = new UrlGroup(_serverSession, Logger); _requestQueue = new RequestQueue(_urlGroup, options.RequestQueueName, options.RequestQueueMode, Logger); _disconnectListener = new DisconnectListener(_requestQueue, Logger); } catch (Exception exception) { // If Url group or request queue creation failed, close server session before throwing. _requestQueue?.Dispose(); _urlGroup?.Dispose(); _serverSession?.Dispose(); Log.HttpSysListenerCtorError(Logger, exception); throw; } }