예제 #1
0
 public void StopAcceptingReads()
 {
     // Can't use dispose (or close) as can be disposed too early by user code
     // As exampled in EngineTests.ZeroContentLengthNotSetAutomaticallyForCertainStatusCodes
     _state = HttpStreamState.Closed;
     _body  = null;
 }
예제 #2
0
 public Streams(IISHttpContext context)
 {
     _context             = context;
     _request             = new HttpRequestStream(_context);
     _response            = new HttpResponseStream(_context, _context);
     _upgradeableResponse = new WrappingStream(_response);
     _upgradeableRequest  = new WrappingStream(_request);
 }
예제 #3
0
 public void StartAcceptingReads(IISHttpContext body)
 {
     // Only start if not aborted
     if (_state == HttpStreamState.Closed)
     {
         _state = HttpStreamState.Open;
         _body  = body;
     }
 }
        ///<inheritdoc/>
        public Task InitializeAsync(AuthenticationScheme scheme, HttpContext context)
        {
            _iisHttpContext = context.Features.Get <IISHttpContext>();
            if (_iisHttpContext == null)
            {
                throw new InvalidOperationException("No IISHttpContext found.");
            }

            Scheme   = scheme;
            _context = context;

            return(Task.CompletedTask);
        }
예제 #5
0
        private static void OnDisconnect(IntPtr pvManagedHttpContext)
        {
            IISHttpContext context = null;

            try
            {
                context = (IISHttpContext)GCHandle.FromIntPtr(pvManagedHttpContext).Target;
                context?.AbortIO(clientDisconnect: true);
            }
            catch (Exception ex)
            {
                context?.Server._logger.LogError(0, ex, $"Unexpected exception in {nameof(IISHttpServer)}.{nameof(OnDisconnect)}.");
            }
        }
예제 #6
0
        private static void CompleteRequest(IISHttpContext context, bool result)
        {
            // Post completion after completing the request to resume the state machine
            context.PostCompletion(ConvertRequestCompletionResults(result));

            if (Interlocked.Decrement(ref context.Server._outstandingRequests) == 0 && context.Server.Stopping)
            {
                // All requests have been drained.
                context.Server._nativeApplication.StopCallsIntoManaged();
                context.Server._shutdownSignal.TrySetResult(null);
            }

            // Dispose the context
            context.Dispose();
        }
예제 #7
0
        private static async Task HandleRequest(IISHttpContext context)
        {
            bool successfulRequest = false;

            try
            {
                successfulRequest = await context.ProcessRequestAsync();
            }
            catch (Exception ex)
            {
                context.Server._logger.LogError("Exception in ProcessRequestAsync", ex);
            }
            finally
            {
                CompleteRequest(context, successfulRequest);
            }
        }
예제 #8
0
        private static NativeMethods.REQUEST_NOTIFICATION_STATUS OnAsyncCompletion(IntPtr pvManagedHttpContext, int hr, int bytes)
        {
            IISHttpContext context = null;

            try
            {
                context = (IISHttpContext)GCHandle.FromIntPtr(pvManagedHttpContext).Target;
                context?.OnAsyncCompletion(hr, bytes);
                return(NativeMethods.REQUEST_NOTIFICATION_STATUS.RQ_NOTIFICATION_PENDING);
            }
            catch (Exception ex)
            {
                context?.Server._logger.LogError(0, ex, $"Unexpected exception in {nameof(IISHttpServer)}.{nameof(OnAsyncCompletion)}.");

                return(NativeMethods.REQUEST_NOTIFICATION_STATUS.RQ_NOTIFICATION_FINISH_REQUEST);
            }
        }
예제 #9
0
        private static async Task HandleRequest(IISHttpContext context)
        {
            bool successfulRequest = false;

            try
            {
                successfulRequest = await context.ProcessRequestAsync();
            }
            catch (Exception ex)
            {
                context.Server._logger.LogError(0, ex, $"Unexpected exception in {nameof(IISHttpServer)}.{nameof(HandleRequest)}.");
            }
            finally
            {
                CompleteRequest(context, successfulRequest);
            }
        }
 public IISHttpRequestBody(IISHttpContext httpContext)
 {
     _httpContext = httpContext;
 }
예제 #11
0
 public HttpResponseStream(IHttpBodyControlFeature bodyControl, IISHttpContext context)
 {
     _bodyControl = bodyControl;
     _context     = context;
     _state       = HttpStreamState.Closed;
 }
예제 #12
0
 public IISHttpResponseBody(IISHttpContext httpContext)
 {
     _httpContext = httpContext;
 }