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; }
internal RequestContext(HttpSysListener server, NativeRequestContext memoryBlob) { // TODO: Verbose log Server = server; _memoryBlob = memoryBlob; Request = new Request(this, _memoryBlob); Response = new Response(this); AllowSynchronousIO = server.Options.AllowSynchronousIO; }
private static void IOCompleted(AsyncAcceptContext asyncContext, uint errorCode, uint numBytes) { bool complete = false; try { if (errorCode != UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS && errorCode != UnsafeNclNativeMethods.ErrorCodes.ERROR_MORE_DATA) { asyncContext.TrySetException(new HttpSysException((int)errorCode)); complete = true; } else { HttpSysListener server = asyncContext.Server; if (errorCode == UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS) { // at this point we have received an unmanaged HTTP_REQUEST and memoryBlob // points to it we need to hook up our authentication handling code here. try { if (server.ValidateRequest(asyncContext._nativeRequestContext) && server.ValidateAuth(asyncContext._nativeRequestContext)) { RequestContext requestContext = new RequestContext(server, asyncContext._nativeRequestContext); asyncContext.TrySetResult(requestContext); complete = true; } } catch (Exception) { server.SendError(asyncContext._nativeRequestContext.RequestId, StatusCodes.Status400BadRequest); throw; } finally { // The request has been handed to the user, which means this code can't reuse the blob. Reset it here. if (complete) { asyncContext._nativeRequestContext = null; } else { asyncContext.AllocateNativeRequest(size: asyncContext._nativeRequestContext.Size); } } } else { // (uint)backingBuffer.Length - AlignmentPadding asyncContext.AllocateNativeRequest(numBytes, asyncContext._nativeRequestContext.RequestId); } // We need to issue a new request, either because auth failed, or because our buffer was too small the first time. if (!complete) { uint statusCode = asyncContext.QueueBeginGetContext(); if (statusCode != UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS && statusCode != UnsafeNclNativeMethods.ErrorCodes.ERROR_IO_PENDING) { // someother bad error, possible(?) return values are: // ERROR_INVALID_HANDLE, ERROR_INSUFFICIENT_BUFFER, ERROR_OPERATION_ABORTED asyncContext.TrySetException(new HttpSysException((int)statusCode)); complete = true; } } if (!complete) { return; } } if (complete) { asyncContext.Dispose(); } } catch (Exception exception) { // Logged by caller asyncContext.TrySetException(exception); asyncContext.Dispose(); } }
internal AsyncAcceptContext(HttpSysListener server) { Server = server; AllocateNativeRequest(); }
public RequestContext(IHttpApplication <TContext> application, MessagePump messagePump, HttpSysListener server, uint?bufferSize, ulong requestId) : base(server, bufferSize, requestId) { _application = application; _messagePump = messagePump; }
public RequestContext(HttpSysListener server, uint?bufferSize, ulong requestId) : base(server.MemoryPool, bufferSize, requestId, server.Options.UseLatin1RequestHeaders) { Server = server; AllowSynchronousIO = server.Options.AllowSynchronousIO; }
internal AsyncAcceptContext(HttpSysListener server) { _server = server; _tcs = new TaskCompletionSource <RequestContext>(); AllocateNativeRequest(); }