Пример #1
0
        RequestDelegate IHttpPipelineAccessPoint <RequestDelegate> .Combine(IHttpPipelineHandler pipeline)
        {
            if (pipeline == null)
            {
                throw new ArgumentNullException(nameof(pipeline));
            }

            return(async context =>
            {
                var request = await CreateRequest(context);


                HttpResponseMessage response;
                try
                {
                    response = await pipeline.ProcessRequest(request, context.RequestAborted);
                }
                catch (OperationCanceledException)
                {
                    throw;
                }
                catch (Exception e)
                {
                    await _exceptionHandler.HandleExceptionAsync(context, e);

                    return;
                }

                await ApplyResponse(context, response);
            });
        }
 public HttpTunnelCombinator(IHttpTunnel tunnel, IHttpPipelineHandler handler, IHttpRequestSerializer requestSerializer, IHttpResponseSerializer responseSerializer)
 {
     Tunnel             = tunnel ?? throw new ArgumentNullException(nameof(tunnel));
     Handler            = handler;
     RequestSerializer  = requestSerializer ?? throw new ArgumentNullException(nameof(requestSerializer));
     ResponseSerializer = responseSerializer ?? throw new ArgumentNullException(nameof(responseSerializer));
 }
Пример #3
0
        /// <summary>
        /// 设置默认情况处理器(当所有路由都不匹配的情况)
        /// </summary>
        /// <param name="handler">处理器</param>
        public void Otherwise(IHttpPipelineHandler handler)
        {
            if (_otherwiseHandler != null)
            {
                throw new InvalidOperationException();
            }

            _otherwiseHandler = handler;
        }
        /// <summary>
        /// 使用 HTTP 请求处理管线
        /// </summary>
        /// <param name="application">ASP.NET Core 应用构建器</param>
        /// <param name="pipeline">HTTP 请求处理管线</param>
        public static void Run(this IApplicationBuilder application, IHttpPipelineHandler pipeline)
        {
            var accessPoint = application.ApplicationServices.GetService <IHttpPipelineAccessPoint <RequestDelegate> >();

            if (accessPoint != null)
            {
                application.Run(accessPoint.Combine(pipeline));
                return;
            }

            throw new InvalidOperationException("asp.net core access point service is not register yet.");
        }
Пример #5
0
            public IHttpPipelineHandler Join(IHttpPipelineHandler downstream)
            {
                _builder.Use(_accessPoint.Combine(downstream));
                var logger = _builder.ApplicationServices.GetService <ILogger <AspNetCoreCombinator> >();

                if (logger != null)
                {
                    logger.LogInformation("http pipeline injected.");
                }

                return(null);
            }
Пример #6
0
        RequestDelegate IHttpPipelineAccessPoint <RequestDelegate> .Combine(IHttpPipelineHandler pipeline)
        {
            if (pipeline == null)
            {
                throw new ArgumentNullException(nameof(pipeline));
            }

            return(async context =>
            {
                var request = await CreateRequest(context);

                var response = await pipeline.ProcessRequest(request);

                await ApplyResponse(context, response);
            });
        }
Пример #7
0
        /// <summary>
        /// implement Join method to route request.
        /// </summary>
        /// <param name="downstream">downstream pipeline handler</param>
        /// <returns>a new pipeline handler with route rules.</returns>
        public IHttpPipelineHandler Join(IHttpPipelineHandler downstream)
        {
            var _rules = Rules.Select(rule => (Func <HttpRequestMessage, IHttpPipelineHandler>)(request =>
            {
                var values = rule.Match(new RouteRequestData(request));
                if (values == null)
                {
                    return(null);
                }

                CreateRouteData(rule, request, values);

                if (rule is IHttpPipeline pipeline)
                {
                    return(pipeline.Join(downstream));
                }

                return(downstream);
            })).ToArray();


            return(new HttpPipelineConditionDistributer(_rules, OtherwiseHandler).AsHandler());
        }
Пример #8
0
 public HttpPipelineHandler(HttpPipeline pipeline, IHttpPipelineHandler downstream)
 {
     _pipeline   = pipeline;
     _downstream = downstream;
 }
Пример #9
0
 /// <summary>
 /// 派生类重写此方法处理请求
 /// </summary>
 /// <param name="request">请求信息</param>
 /// <param name="downstream">downstream pipeline request handler</param>
 /// <returns>响应信息</returns>
 protected virtual ValueTask <HttpResponseMessage> ProcessRequest(HttpRequestMessage request, IHttpPipelineHandler downstream)
 {
     return(downstream.ProcessRequest(request));
 }
Пример #10
0
 /// <summary>
 /// join downstream pipeline
 /// </summary>
 /// <param name="downstream">downstream pipeline</param>
 /// <returns></returns>
 public IHttpPipelineHandler Join(IHttpPipelineHandler downstream)
 {
     return(new HttpPipelineHandler(this, downstream));
 }
Пример #11
0
        public IHttpPipelineHandler Join(IHttpPipelineHandler downstream)
        {
            var distributer = new HttpPipelineBalanceDistributer(_pipelines.Select(item => item.Join(downstream)).ToArray());

            return(distributer.AsHandler());
        }
 public IHttpPipelineHandler Join(IHttpPipelineHandler downstream)
 {
     return(AsPipeline().Join(downstream));
 }
Пример #13
0
 protected override ValueTask <HttpResponseMessage> ProcessRequest(HttpRequestMessage request, IHttpPipelineHandler downstream, CancellationToken cancellationToken)
 {
     request = _func(request);
     return(downstream.ProcessRequest(request, cancellationToken));
 }
Пример #14
0
 public IHttpPipelineHandler Join(IHttpPipelineHandler downstream)
 {
     _combinedAction(Combined = _accessPoint.Combine(downstream));
     return(null);
 }
        /// <summary>
        /// run asp.net core site with pipeline.
        /// </summary>
        /// <param name="builder">asp.net core application builder</param>
        /// <param name="pipeline">HTTP pipeline</param>
        public static void RunPipeline(this IApplicationBuilder builder, IHttpPipelineHandler pipeline)
        {
            var accessPoint = builder.ApplicationServices.GetRequiredService <IHttpPipelineAccessPoint <RequestDelegate> >();

            builder.Run(accessPoint.Combine(pipeline));
        }
Пример #16
0
 /// <summary>
 /// 创建 HttpPipelineConditionDispatcher 对象
 /// </summary>
 /// <param name="rules">分发规则</param>
 /// <param name="defaultHandler">默认处理管线</param>
 public HttpPipelineConditionDistributer(Func <HttpRequestMessage, IHttpPipelineHandler>[] rules, IHttpPipelineHandler defaultHandler)
 {
     Rules          = rules ?? throw new ArgumentNullException(nameof(rules));
     DefaultHandler = defaultHandler ?? throw new ArgumentNullException(nameof(defaultHandler));
 }
Пример #17
0
 public HttpHandler(IHttpPipelineHandler handler)
 {
     Handler = handler;
 }
Пример #18
0
 /// <summary>
 /// create a HttpMessageHandler instance to access HTTP pipeline.
 /// </summary>
 /// <param name="pipeline"></param>
 /// <returns></returns>
 public HttpMessageHandler Combine(IHttpPipelineHandler pipeline)
 {
     return(new HttpHandler(pipeline));
 }
Пример #19
0
 public IHttpPipelineHandler Join(IHttpPipelineHandler downstream)
 {
     return(_pipeline(downstream));
 }
Пример #20
0
 public IHttpPipelineHandler Join(IHttpPipelineHandler downstream)
 {
     throw new NotImplementedException();
 }
Пример #21
0
 public IHttpPipelineHandler Join(IHttpPipelineHandler handler)
 {
     return(new RewritePipelineHandler(this, handler));
 }
Пример #22
0
 /// <summary>
 /// create a HttpPipelineRouteService instance
 /// </summary>
 /// <param name="otherwiseHandler">handler that handle request when there is no rule match</param>
 /// <param name="rules">route rules</param>
 public HttpPipelineRouter(IHttpPipelineHandler otherwiseHandler, params IHttpPipelineRouteRule[] rules)
 {
     OtherwiseHandler = otherwiseHandler ?? throw new ArgumentNullException(nameof(otherwiseHandler));
     Rules            = rules ?? throw new ArgumentNullException(nameof(rules));
 }
Пример #23
0
 public HttpHandlerWithDiagnosticListener(DiagnosticListener listener, IHttpPipelineHandler handler)
 {
     _listener = listener ?? throw new ArgumentNullException(nameof(listener));
     _handler  = handler ?? throw new ArgumentNullException(nameof(handler));
 }
Пример #24
0
 public RewritePipelineHandler(IHttpPipelineRewriteRule rewriter, IHttpPipelineHandler handler)
 {
     _rewriter     = rewriter;
     this._handler = handler;
 }
Пример #25
0
 IHttpPipelineHandler IHttpPipeline.Join(IHttpPipelineHandler handler)
 {
     return(_upstream.Join(_downstream.Join(handler)));
 }
Пример #26
0
 /// <summary>
 /// use a router.
 /// </summary>
 /// <param name="pipeline">pipeline to use router</param>
 /// <param name="otherwise">handler that handle request when no rule matches.</param>
 /// <param name="rules">route rules</param>
 /// <returns>pipeline with router</returns>
 public static IHttpPipeline UseRouter(this IHttpPipeline pipeline, IHttpPipelineHandler otherwise, params IHttpPipelineRouteRule[] rules)
 {
     return(pipeline.Join(new HttpPipelineRouter(otherwise, rules)));
 }