コード例 #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            //app.UseHttpsRedirection();
            //app.UseMvc();

            var configuration = new OcelotPipelineConfiguration
            {
                PreErrorResponderMiddleware = async(ctx, next) =>
                {
                    Console.WriteLine("in OcelotPipelineConfiguration");
                    //String token = ctx.HttpContext.Request.Headers["token"].FirstOrDefault();//这里可以进行接收的客户端token解析转发
                    ctx.HttpContext.Request.Headers.Add("X-Hello", "666");
                    await next.Invoke();

                    Console.WriteLine("out OcelotPipelineConfiguration");
                }
            };

            app.UseOcelot(configuration).Wait(); // 不要忘记了写 wait
        }
コード例 #2
0
        public static IWebHost BuildWebHost(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
        .UseKestrel()
        .ConfigureAppConfiguration((hostingContext, config) =>
        {
            config
            .SetBasePath(hostingContext.HostingEnvironment.ContentRootPath)
            .AddJsonFile("appsettings.json", true, true)
            .AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", true, true)
            .AddJsonFile("ocelot.json")
            .AddJsonFile($"ocelot.{hostingContext.HostingEnvironment.EnvironmentName}.json", true, true)
            .AddEnvironmentVariables();
        })
        .ConfigureServices(services =>
        {
            services.AddGrpcJsonTranscoder(() => new GrpcAssemblyResolver().ConfigGrpcAssembly(typeof(Greeter.GreeterClient).Assembly));
            services.AddOcelot();
            services.AddHttpContextAccessor();
        })
        .Configure(app =>
        {
            var configuration = new OcelotPipelineConfiguration
            {
                PreQueryStringBuilderMiddleware = async(ctx, next) =>
                {
                    await ctx.HandleGrpcRequestAsync(next);
                }
            };

            app.UseOcelot(configuration).Wait();
        })
        .Build();
コード例 #3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapHealthChecks("/health");
            });

            var configuration = new OcelotPipelineConfiguration
            {
                AuthorisationMiddleware = async(ctx, next) =>
                {
                    var user = ctx.HttpContext.User;
                    await next.Invoke();
                }
            };

            app.UseAuthentication();

            app.UseOcelot(configuration).Wait();
        }
コード例 #4
0
        private static OcelotPipelineConfiguration SetConfig()
        {
            var configuration = new OcelotPipelineConfiguration
            {
                PreErrorResponderMiddleware = async(ctx, next) =>
                {
                    var req = ctx.Request;

                    if (req.Headers["Authorization"][0] == "1")
                    {
                        var response = ctx.Response;
                        response.ContentType       = "application/json";
                        response.StatusCode        = 403;
                        response.Headers["Answer"] = "miss";

                        var strResult = "some miss";
                        await ctx.Response.Body.WriteAsync(Encoding.UTF8.GetBytes(strResult));

                        //var error = new UnauthenticatedError("Request for authenticated route was unauthenticated");
                        //ctx.Errors.Add(error);
                    }
                    else
                    {
                        await next.Invoke();
                    }
                }
            };

            return(configuration);
        }
コード例 #5
0
ファイル: Startup.cs プロジェクト: JakubMrowca/Micro
        public async void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            var configuration = new OcelotPipelineConfiguration
            {
                AuthorisationMiddleware = async(ctx, next) =>
                {
                    if (this.Authorize(ctx))
                    {
                        await next.Invoke();
                    }
                    else
                    {
                        ctx.Errors.Add(new UnauthorisedError($"Fail to authorize"));
                    }
                }
            };

            app.UseCors("MyPolicy");

            app.UseSignalR(routes => { routes.MapHub <UserHub>("/userHub"); });

            app.UseAuthentication();

            app.UseMvc();
            await app.UseOcelot(configuration);
        }
コード例 #6
0
        public static IWebHost BuildWebHost(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
        .UseKestrel()
        .ConfigureAppConfiguration((hostingContext, config) =>
        {
            config
            .SetBasePath(hostingContext.HostingEnvironment.ContentRootPath)
            .AddJsonFile("appsettings.json", true, true)
            .AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", true, true)
            .AddJsonFile("ocelot.json")
            .AddJsonFile($"ocelot.{hostingContext.HostingEnvironment.EnvironmentName}.json", true, true)
            .AddEnvironmentVariables();
        })
        .ConfigureServices(services =>
        {
            services.AddGrpcJsonTranscoder(() => new GrpcAssemblyResolver().ConfigGrpcAssembly(typeof(Greeter.GreeterClient).Assembly));
            services.AddOcelot();
            services.AddHttpContextAccessor();
        })
        .Configure(app =>
        {
            var configuration = new OcelotPipelineConfiguration
            {
                PreQueryStringBuilderMiddleware = async(ctx, next) =>
                {
                    // https://stackoverflow.com/questions/54960613/how-to-create-callcredentials-from-sslcredentials-and-token-string
                    await ctx.HandleGrpcRequestAsync(next /*, new SslCredentials(File.ReadAllText("Certs/server.crt"))*/);
                }
            };

            app.UseOcelot(configuration).Wait();
        })
        .Build();
コード例 #7
0
        async public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            // Pipeline de auth customizado para múltiplas roles - Comentar para voltar para o default
            var configuration = new OcelotPipelineConfiguration
            {
                AuthorisationMiddleware = async(ctx, next) =>
                {
                    if (CustomAuthenticationPipeline.Execute(ctx))
                    {
                        await next.Invoke();
                    }
                    else
                    {
                        ctx.Errors.Add(new UnauthorisedError($"Fail to authorize"));
                    }
                }
            };

            await app.UseOcelot(configuration);
        }
コード例 #8
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseHttpsRedirection();



            var conf = new OcelotPipelineConfiguration
            {
                PreErrorResponderMiddleware = async(ctx, next) =>
                {
                    await next.Invoke();
                }
            };

            app.UseOcelot(conf);

            app.UseMvc();
        }
コード例 #9
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            app.UseExceptionHandler(new ExceptionHandlerOptions
            {
                ExceptionHandler = new ExceptionHandler().Invoke
            });

            var configuration = new OcelotPipelineConfiguration
            {
                AuthorisationMiddleware = async(ctx, next) =>
                {
                    var user = ctx.HttpContext.User;

                    var userIdentityHeader = new AddHeader("userIdentity", "");
                    ctx.DownstreamReRoute.AddHeadersToUpstream.Add(userIdentityHeader);

                    await next.Invoke();
                }
            };

            app.UseCors("*");

            app.UseAuthentication();

            app.UseWebSockets();
            app.UseOcelot(configuration).Wait();

            app.UseMvc();
        }
コード例 #10
0
        /// <summary>
        /// 配置请求管道
        /// </summary>
        /// <param name="app"></param>
        public void Configure(IApplicationBuilder app)
        {
            // 使用跨域
            app.UseCors("CorsPolicy");
            // 网关扩展中间件配置
            var configuration = new OcelotPipelineConfiguration()
            {
                // 扩展为健康检查地址
                PreErrorResponderMiddleware = async(ctx, next) =>
                {
                    if (ctx.HttpContext.Request.Path.Equals(new PathString("/")))
                    {
                        await ctx.HttpContext.Response.WriteAsync("ok");
                    }
                    else
                    {
                        await next.Invoke();
                    }
                },
            };

            // 增加DotNetty请求通道,因为最终会阻断通道,所以要包含部分中间件功能
            configuration.MapWhenOcelotPipeline.Add((build) =>
            {
                return((context) => context.DownstreamReRoute.DownstreamScheme.ToLower() == "netty");
            });
            // 使用监控

            // 使用网关
            app.UseOcelot(configuration).Wait();
            // Welcome
            Console.WriteLine(Welcome());
        }
コード例 #11
0
        public async void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            // -- Loging
            loggerFactory.AddNLog();
            loggerFactory.ConfigureNLog("nlog.config");
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            app.UseOcelot().Wait();
            // -- Loging

            var configuration = new OcelotPipelineConfiguration
            {
                PreQueryStringBuilderMiddleware = async(ctx, next) =>
                {
                    await next.Invoke();
                }
            };


            app.UseAuthentication(); // auth
            app.UseMvc();
            await app.UseOcelot(configuration);
        }
コード例 #12
0
ファイル: Startup.cs プロジェクト: zhjgstc/AspNetCoreCloud
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            var jwtSecret = Configuration["jwt.secret"];

            var configuration = new OcelotPipelineConfiguration
            {
                AuthenticationMiddleware = async(ctx, next) =>
                {
                    LoginFilter loginFilter = new LoginFilter();
                    string      json        = "";
                    var         flag        = loginFilter.NeedLogin(ctx.HttpContext, Configuration, out json);
                    if (!flag)
                    {
                        await ctx.HttpContext.Response.WriteAsync(json);

                        return;
                    }
                    await next.Invoke();
                }
            };

            app.UseOcelot(configuration).Wait();
            app.Run(async(context) =>
            {
                await context.Response.WriteAsync("");
            });
        }
コード例 #13
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            var config = new OcelotPipelineConfiguration
            {
                AuthorisationMiddleware
                    = async(downStreamContext, next) =>
                      await OcelotJwtMiddleware.CreateAuthorizationFilter(downStreamContext, next)
            };

            app.UseHttpsRedirection();

            app.UseRouting();
            app.UseCors(x => x
                        .AllowAnyMethod()
                        .AllowAnyHeader()
                        .SetIsOriginAllowed(origin => true)
                        .AllowCredentials());

            app.UseAuthorization();

            app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
            app.UseOcelot(config).Wait();
        }
コード例 #14
0
ファイル: Startup.cs プロジェクト: r4f3t/CqrsSampleCodeFirst
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public async void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            var configuration = new OcelotPipelineConfiguration
            {
                PreQueryStringBuilderMiddleware = async(ctx, next) =>
                {
                    await next.Invoke();
                }
            };

            await app.UseOcelot(configuration);
        }
コード例 #15
0
        public static async Task <IApplicationBuilder> UseExtOcelot(this IApplicationBuilder builder, Action <OcelotPipelineConfiguration> pipelineConfiguration)
        {
            var config = new OcelotPipelineConfiguration();

            pipelineConfiguration?.Invoke(config);
            return(await builder.UseExtOcelot(config));
        }
コード例 #16
0
        /// <summary>
        /// 配置请求管道
        /// </summary>
        /// <param name="app"></param>
        public void Configure(IApplicationBuilder app)
        {
            // 使用跨域
            app.UseCors("CorsPolicy");
            // 使用监控
            //app.UseAppMetrics();
            // 网关扩展中间件配置
            var configuration = new OcelotPipelineConfiguration()
            {
                // 扩展为健康检查地址
                PreErrorResponderMiddleware = async(ctx, next) =>
                {
                    if (ctx.HttpContext.Request.Path.Equals(new PathString("/")))
                    {
                        await ctx.HttpContext.Response.WriteAsync("ok");
                    }
                    else
                    {
                        await next.Invoke();
                    }
                },
            };

            // 增加DotNetty请求通道,因为最终会阻断通道,所以要包含部分中间件功能
            //configuration.MapWhenOcelotPipeline.Add(new DotNettyOcelotPipeline().DotNettyPipeline);
            // 使用网关
            app.UseOcelot(configuration).Wait();
            // Welcome
            Console.WriteLine(Welcome());
        }
コード例 #17
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            //app.UseHttpsRedirection();

            app.UseAuthorization();
            app.UseCors("CorsPolicy");


            var configuration = new OcelotPipelineConfiguration
            {
                AuthorisationMiddleware = async(ctx, next) =>
                {
                    if (this.Authorize(ctx))
                    {
                        await next.Invoke();
                    }
                    else
                    {
                        ctx.Errors.Add(new UnauthorisedError($"Fail to authorize"));
                    }
                }
            };


            app.UseOcelot(configuration).Wait();
        }
        public static async Task <IApplicationBuilder> UseOcelot(this IApplicationBuilder builder, Action <OcelotPipelineConfiguration> pipelineConfiguration)
        {
            OcelotPipelineConfiguration ocelotPipelineConfiguration = new OcelotPipelineConfiguration();

            pipelineConfiguration?.Invoke(ocelotPipelineConfiguration);
            return(await builder.UseOcelot(ocelotPipelineConfiguration));
        }
コード例 #19
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            var configration = new OcelotPipelineConfiguration
            {
                AuthorisationMiddleware = async(ctx, next) =>
                {
                    if (Authorize(ctx))
                    {
                        await next.Invoke();
                    }
                    else
                    {
                        ctx.Items.SetError(new UnauthorisedError($"Fail to authorize"));
                    }
                }
            };

            //your code here
            app.UseOcelot(configration).Wait();
        }
コード例 #20
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            app.UseCustomExceptionMiddleware();
            // app.UseMvc();
            // 啟用路由
            app.UseRouting();
            // 啟用驗證
            app.UseAuthentication();
            // 啟用授權
            app.UseAuthorization();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
            var configuration = new OcelotPipelineConfiguration
            {
                PreErrorResponderMiddleware = async(ctx, next) =>
                {
                    await next.Invoke();

                    System.Console.WriteLine(ctx.Response.StatusCode.ToString());
                }
            };

            app.UseOcelot(configuration);
        }
コード例 #21
0
ファイル: Steps.cs プロジェクト: zhikecore/Ocelot
        /// <summary>
        /// This is annoying cos it should be in the constructor but we need to set up the file before calling startup so its a step.
        /// </summary>
        public void GivenOcelotIsRunning(OcelotPipelineConfiguration ocelotPipelineConfig)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: false)
                          .AddJsonFile("ocelot.json", false, false)
                          .AddEnvironmentVariables();

            var configuration = builder.Build();

            _webHostBuilder = new WebHostBuilder();
            _webHostBuilder.ConfigureServices(s =>
            {
                s.AddSingleton(_webHostBuilder);
            });

            _ocelotServer = new TestServer(_webHostBuilder
                                           .UseConfiguration(configuration)
                                           .ConfigureServices(s =>
            {
                s.AddOcelot(configuration);
            })
                                           .ConfigureLogging(l =>
            {
                l.AddConsole();
                l.AddDebug();
            })
                                           .Configure(a =>
            {
                a.UseOcelot(ocelotPipelineConfig).Wait();
            }));

            _ocelotClient = _ocelotServer.CreateClient();
        }
コード例 #22
0
ファイル: Startup.cs プロジェクト: z5616342/FamilyBucket
        /// <summary>
        /// 配置请求管道
        /// </summary>
        /// <param name="app"></param>
        /// <param name="env"></param>
        /// <param name="loggerFactory"></param>
        /// <param name="appLifetime"></param>
        public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory, IApplicationLifetime appLifetime)
        {
            // 使用跨域
            app.UseCors("CorsPolicy");
            // 健康检查地址
            var conf = new OcelotPipelineConfiguration()
            {
                PreErrorResponderMiddleware = async(ctx, next) =>
                {
                    if (ctx.HttpContext.Request.Path.Equals(new PathString("/")))
                    {
                        await ctx.HttpContext.Response.WriteAsync("ok");
                    }
                    else
                    {
                        await next.Invoke();
                    }
                }
            };

            // 使用监控

            // 使用网关
            app.UseOcelot(conf).Wait();
            // 日志,事件驱动日志
            loggerFactory.AddBucketLog(app, Configuration.GetValue <string>("Project:Name"));
            // Autofac容器释放
            appLifetime.ApplicationStopped.Register(() => { AutofacContainer.Dispose(); });
            // Welcome
            Console.WriteLine(Welcome());
        }
コード例 #23
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            var configuration = new OcelotPipelineConfiguration
            {
                PreErrorResponderMiddleware = async(ctx, next) =>
                {
                    await next.Invoke();
                },
                PreAuthenticationMiddleware = async(ctx, next) =>
                {
                    await next.Invoke();
                }
            };

            app.UseOcelot(configuration).Wait();
            app.UseMvc();
        }
コード例 #24
0
ファイル: Startup.cs プロジェクト: njarma/bitsa
        public async void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            // -- Loging
            loggerFactory.AddNLog();
            loggerFactory.ConfigureNLog("nlog.config");
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            app.UseOcelot().Wait();
            // -- Loging

            var configuration = new OcelotPipelineConfiguration
            {
                PreQueryStringBuilderMiddleware = async(ctx, next) =>
                {
                    var name = ctx.HttpContext.User.Identity.Name;
                    //Console.WriteLine(name);
                    //Log.Information($"{name}");
                    await next.Invoke();
                }
            };

            app.UseCors("AllowOrigin");
            app.UseAuthentication(); // auth

            app.UseMvc();
            await app.UseOcelot(configuration);
        }
コード例 #25
0
ファイル: Startup.cs プロジェクト: qkb/microservice-demo
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            //Об╚вол╝С╝■
            var configuration = new OcelotPipelineConfiguration
            {
                PreErrorResponderMiddleware = async(ctx, next) =>
                {
                    ctx.HttpContext.Request.Headers.Add("myreq", "ocelot-request");
                    await next.Invoke();
                }
            };

            app.UseOcelot(configuration).Wait();

            //app.UseOcelot().Wait();
        }
コード例 #26
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            var configuration = new OcelotPipelineConfiguration {
                PreErrorResponderMiddleware = async(ctx, next) => {
                    var path   = ctx.Request.Path;
                    var method = ctx.Request.Method;
                    Console.WriteLine("Request -- [{1}] {0}", path, method);

                    var auth = ctx.Request.Headers["Authorization"];
                    if (auth.Count == 0)
                    {
                        ctx.Request.Headers.Add("Authorization", "Basic YXBpOm9yMjAyMGFwaQ==");
                    }

                    await next.Invoke();
                },
            };

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();
            app.UseRouting();
            app.UseAuthorization();
            app.UseEndpoints(endpoints => {
                endpoints.MapControllers();
            });
            app.UseOcelot(configuration).Wait();
        }
コード例 #27
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseRouting();

            // app.UseEndpoints(endpoints =>
            // {
            //     endpoints.MapGet("/", async context =>
            //     {
            //         await context.Response.WriteAsync("Hello World!");
            //     });
            // });
            var configuration = new OcelotPipelineConfiguration
            {
                PreQueryStringBuilderMiddleware = async(ctx, next) =>
                {
                    await next.Invoke();

                    //add code here because all middleware as run at this point and the request is going to go back up the pipeline.
                }
            };

            app.UseOcelot(configuration).Wait();
        }
コード例 #28
0
ファイル: Extensions.cs プロジェクト: qkb/identity-demo
        public static IOcelotPipelineBuilder BuildCustomOcelotPipeline(this IOcelotPipelineBuilder builder,
                                                                       OcelotPipelineConfiguration pipelineConfiguration)
        {
            builder.UseExceptionHandlerMiddleware();
            builder.MapWhen(context => context.HttpContext.WebSockets.IsWebSocketRequest,
                            app =>
            {
                app.UseDownstreamRouteFinderMiddleware();
                app.UseDownstreamRequestInitialiser();
                app.UseLoadBalancingMiddleware();
                app.UseDownstreamUrlCreatorMiddleware();
                app.UseWebSocketsProxyMiddleware();
            });
            builder.UseIfNotNull(pipelineConfiguration.PreErrorResponderMiddleware);
            builder.UseResponderMiddleware();
            builder.UseDownstreamRouteFinderMiddleware();
            builder.UseSecurityMiddleware();
            if (pipelineConfiguration.MapWhenOcelotPipeline != null)
            {
                foreach (var pipeline in pipelineConfiguration.MapWhenOcelotPipeline)
                {
                    builder.MapWhen(pipeline);
                }
            }
            builder.UseHttpHeadersTransformationMiddleware();
            builder.UseDownstreamRequestInitialiser();
            builder.UseRateLimiting();

            builder.UseRequestIdMiddleware();
            builder.UseIfNotNull(pipelineConfiguration.PreAuthenticationMiddleware);
            if (pipelineConfiguration.AuthenticationMiddleware == null)
            {
                builder.UseAuthenticationMiddleware();
            }
            else
            {
                builder.Use(pipelineConfiguration.AuthenticationMiddleware);
            }
            builder.UseClaimsToClaimsMiddleware();
            builder.UseIfNotNull(pipelineConfiguration.PreAuthorisationMiddleware);
            if (pipelineConfiguration.AuthorisationMiddleware == null)
            {
                builder.UseAuthorisationMiddleware();
            }
            else
            {
                builder.Use(pipelineConfiguration.AuthorisationMiddleware);
            }
            builder.UseClaimsToHeadersMiddleware();
            builder.UseIfNotNull(pipelineConfiguration.PreQueryStringBuilderMiddleware);
            builder.UseClaimsToQueryStringMiddleware();
            builder.UseLoadBalancingMiddleware();
            builder.UseDownstreamUrlCreatorMiddleware();
            builder.UseOutputCacheMiddleware();
            builder.UseHttpRequesterMiddleware();

            return(builder);
        }
コード例 #29
0
        public static Task <IApplicationBuilder> UseOcelot(this IApplicationBuilder app,
                                                           Action <OcelotPipelineConfiguration> pipelineConfigurationAction,
                                                           Action <IOcelotPipelineBuilder, OcelotPipelineConfiguration> builderAction)
        {
            var pipelineConfiguration = new OcelotPipelineConfiguration();

            pipelineConfigurationAction?.Invoke(pipelineConfiguration);
            return(UseOcelot(app, builderAction, pipelineConfiguration));
        }
コード例 #30
0
        public static IApplicationBuilder UseOcelotWhenRouteMatch(this IApplicationBuilder app,
                                                                  Action <OcelotPipelineConfiguration> pipelineConfigurationAction,
                                                                  Action <IOcelotPipelineBuilder, OcelotPipelineConfiguration> builderAction)
        {
            var pipelineConfiguration = new OcelotPipelineConfiguration();

            pipelineConfigurationAction?.Invoke(pipelineConfiguration);
            return(UseOcelotWhenRouteMatch(app, builderAction, pipelineConfiguration));
        }