A class that represents the complete context for an HTTP request.
Inheritance: IStumpsHttpContext
        public void InitializeInstance_CalledTwice_ThrowsException()
        {
            var stumpsContext = new StumpsHttpContext();

            Assert.ThrowsAsync <ArgumentNullException>(async() => await stumpsContext.InitializeInstance(null));
            Assert.ThrowsAsync <InvalidOperationException>(async() => await stumpsContext.InitializeInstance(null));
        }
        public void InitializeInstance_WithNullContext_ThrowsException()
        {
            var stumpsContext = new StumpsHttpContext();

            var ex = Assert.ThrowsAsync <ArgumentNullException>(async() => await stumpsContext.InitializeInstance(null));

            Assert.That(ex.ParamName.Equals("context", StringComparison.Ordinal));
        }
示例#3
0
        /// <summary>
        ///     Processes the incoming HTTP request asynchronously.
        /// </summary>
        /// <param name="asyncResult">The asynchronous result.</param>
        private async void ProcessAsyncRequest()
        {

            if (_listener == null)
            {
                return;
            }

            try
            {
                // Gets the HTTP context for the request
                var context = await _listener.GetContextAsync();
                WaitForConnections();

                // Create a new StumpsHttpContext
                var stumpsContext = new StumpsHttpContext(context);

                if (this.RequestReceived != null)
                {
                    this.RequestReceived(this, new StumpsContextEventArgs(stumpsContext));
                }

                // Process the request through the HTTP handler
                var processResult = await _handler.ProcessRequest(stumpsContext);

                if (this.RequestProcessed != null)
                {
                    this.RequestProcessed(this, new StumpsContextEventArgs(stumpsContext));
                }

                var abortConnection = processResult == ProcessHandlerResult.DropConnection;

                // End the request
                stumpsContext.EndResponse(abortConnection);

                if (this.RequestFinished != null)
                {
                    this.RequestFinished(this, new StumpsContextEventArgs(stumpsContext));
                }

            }
            catch (HttpListenerException)
            {
            }
            catch (InvalidOperationException)
            {
            }

        }