当前位置: 首页>>代码示例>>C#>>正文


C# RequestState.CompleteResponse方法代码示例

本文整理汇总了C#中RequestState.CompleteResponse方法的典型用法代码示例。如果您正苦于以下问题:C# RequestState.CompleteResponse方法的具体用法?C# RequestState.CompleteResponse怎么用?C# RequestState.CompleteResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RequestState的用法示例。


在下文中一共展示了RequestState.CompleteResponse方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SendAsync

        /// <summary>
        /// This adapts HttpRequestMessages to ASP.NET requests, dispatches them through the pipeline, and returns the
        /// associated HttpResponseMessage.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        protected override async Task<HttpResponseMessage> SendAsync(
            HttpRequestMessage request,
            CancellationToken cancellationToken)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var state = new RequestState(request, _pathBase, _application);
            var requestContent = request.Content ?? new StreamContent(Stream.Null);
            var body = await requestContent.ReadAsStreamAsync();
            if (body.CanSeek)
            {
                // This body may have been consumed before, rewind it.
                body.Seek(0, SeekOrigin.Begin);
            }
            state.Context.HttpContext.Request.Body = body;
            var registration = cancellationToken.Register(state.AbortRequest);

            // Async offload, don't let the test code block the caller.
            var offload = Task.Factory.StartNew(async () =>
                {
                    try
                    {
                        await _application.ProcessRequestAsync(state.Context);
                        state.CompleteResponse();
                        state.ServerCleanup(exception: null);
                    }
                    catch (Exception ex)
                    {
                        state.Abort(ex);
                        state.ServerCleanup(ex);
                    }
                    finally
                    {
                        registration.Dispose();
                    }
                });

            return await state.ResponseTask.ConfigureAwait(false);
        }
开发者ID:leloulight,项目名称:Hosting,代码行数:49,代码来源:ClientHandler.cs

示例2: SendAsync

        /// <summary>
        /// This adapts HttpRequestMessages to OWIN requests, dispatches them through the OWIN pipeline, and returns the
        /// associated HttpResponseMessage.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        protected override async Task<HttpResponseMessage> SendAsync(
            HttpRequestMessage request,
            CancellationToken cancellationToken)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            var state = new RequestState(request, cancellationToken);
            HttpContent requestContent = request.Content ?? new StreamContent(Stream.Null);
            Stream body = await requestContent.ReadAsStreamAsync();
            if (body.CanSeek)
            {
                // This body may have been consumed before, rewind it.
                body.Seek(0, SeekOrigin.Begin);
            }
            state.OwinContext.Request.Body = body;
            CancellationTokenRegistration registration = cancellationToken.Register(state.Abort);

            // Async offload, don't let the test code block the caller.
            Task offload = Task.Factory.StartNew(async () =>
                {
                    try
                    {
                        await _next(state.Environment);
                        state.CompleteResponse();
                    }
                    catch (Exception ex)
                    {
                        state.Abort(ex);
                    }
                    finally
                    {
                        registration.Dispose();
                        state.Dispose();
                    }
                });

            return await state.ResponseTask;
        }
开发者ID:Kstal,项目名称:Microsoft.Owin,代码行数:48,代码来源:OwinClientHandler.cs

示例3: SendAsync

        /// <summary>
        /// This adapts HttpRequestMessages to ASP.NET requests, dispatches them through the pipeline, and returns the
        /// associated HttpResponseMessage.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        protected override async Task<HttpResponseMessage> SendAsync(
            [NotNull] HttpRequestMessage request,
            CancellationToken cancellationToken)
        {
            var state = new RequestState(request, _pathBase, cancellationToken);
            var requestContent = request.Content ?? new StreamContent(Stream.Null);
            var body = await requestContent.ReadAsStreamAsync();
            if (body.CanSeek)
            {
                // This body may have been consumed before, rewind it.
                body.Seek(0, SeekOrigin.Begin);
            }
            state.HttpContext.Request.Body = body;
            var registration = cancellationToken.Register(state.Abort);

            // Async offload, don't let the test code block the caller.
            var offload = Task.Factory.StartNew(async () =>
                {
                    try
                    {
                        await _next(state.FeatureCollection);
                        state.CompleteResponse();
                    }
                    catch (Exception ex)
                    {
                        state.Abort(ex);
                    }
                    finally
                    {
                        registration.Dispose();
                        state.Dispose();
                    }
                });

            return await state.ResponseTask;
        }
开发者ID:humblelistener,项目名称:Hosting,代码行数:43,代码来源:ClientHandler.cs

示例4: SendInternalAsync

        private async Task<HttpResponseMessage> SendInternalAsync(
            HttpRequestMessage request,
            CancellationToken cancellationToken)
        {
            if (_useCookies)
            {
                string cookieHeader = _cookieContainer.GetCookieHeader(request.RequestUri);
                if (!string.IsNullOrEmpty(cookieHeader))
                {
                    request.Headers.Add("Cookie", cookieHeader);
                }
            }

            var state = new RequestState(request, cancellationToken);
            HttpContent requestContent = request.Content ?? new StreamContent(Stream.Null);
            Stream body = await requestContent.ReadAsStreamAsync().NotOnCapturedContext();
            if (body.CanSeek)
            {
                // This body may have been consumed before, rewind it.
                body.Seek(0, SeekOrigin.Begin);
            }
            state.OwinContext.Request.Body = body;
            CancellationTokenRegistration registration = cancellationToken.Register(state.Abort);

            // Async offload, don't let the test code block the caller.
            Task offload = Task.Run(async () =>
            {
                try
                {
                    await _appFunc(state.Environment).NotOnCapturedContext();
                    state.CompleteResponse();
                }
                catch (Exception ex)
                {
                    state.Abort(ex);
                }
                finally
                {
                    registration.Dispose();
                    state.Dispose();
                }
            }, cancellationToken);

            HttpResponseMessage response = await state.ResponseTask.NotOnCapturedContext();
            if (_useCookies && response.Headers.Contains("Set-Cookie"))
            {
                string cookieHeader = string.Join(",", response.Headers.GetValues("Set-Cookie"));
                _cookieContainer.SetCookies(request.RequestUri, cookieHeader);
            }
            return response;
        }
开发者ID:devlead,项目名称:OwinHttpMessageHandler,代码行数:51,代码来源:OwinHttpMessageHandler.cs


注:本文中的RequestState.CompleteResponse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。