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)); }
/// <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."); }
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); }
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); }); }
/// <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()); }
public HttpPipelineHandler(HttpPipeline pipeline, IHttpPipelineHandler downstream) { _pipeline = pipeline; _downstream = downstream; }
/// <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)); }
/// <summary> /// join downstream pipeline /// </summary> /// <param name="downstream">downstream pipeline</param> /// <returns></returns> public IHttpPipelineHandler Join(IHttpPipelineHandler downstream) { return(new HttpPipelineHandler(this, downstream)); }
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)); }
protected override ValueTask <HttpResponseMessage> ProcessRequest(HttpRequestMessage request, IHttpPipelineHandler downstream, CancellationToken cancellationToken) { request = _func(request); return(downstream.ProcessRequest(request, cancellationToken)); }
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)); }
/// <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)); }
public HttpHandler(IHttpPipelineHandler handler) { Handler = handler; }
/// <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)); }
public IHttpPipelineHandler Join(IHttpPipelineHandler downstream) { return(_pipeline(downstream)); }
public IHttpPipelineHandler Join(IHttpPipelineHandler downstream) { throw new NotImplementedException(); }
public IHttpPipelineHandler Join(IHttpPipelineHandler handler) { return(new RewritePipelineHandler(this, handler)); }
/// <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)); }
public HttpHandlerWithDiagnosticListener(DiagnosticListener listener, IHttpPipelineHandler handler) { _listener = listener ?? throw new ArgumentNullException(nameof(listener)); _handler = handler ?? throw new ArgumentNullException(nameof(handler)); }
public RewritePipelineHandler(IHttpPipelineRewriteRule rewriter, IHttpPipelineHandler handler) { _rewriter = rewriter; this._handler = handler; }
IHttpPipelineHandler IHttpPipeline.Join(IHttpPipelineHandler handler) { return(_upstream.Join(_downstream.Join(handler))); }
/// <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))); }