/// <summary> /// 返回是否授权通过。 /// </summary> /// <param name="context"></param> /// <param name="option"></param> /// <returns></returns> internal static bool IsAuthenticated(HttpContext context, MicroServiceOption option) { if ((option.UseAuthentication && !context.User.Identity.IsAuthenticated) || (!string.IsNullOrEmpty(option.IpWhiteAddress) && !ValidateIpAddress(GetIpAddress(context), option.IpWhiteAddress))) { return(false); } return(true); }
private static async Task ProcessDiscoverAsync(HttpContext context, MicroServiceOption option) { var url = context.Request.Scheme + "://" + context.Request.Host.Value + option.Path; var handlers = definitions.Select(s => s.Key).ToArray(); var response = new ResponseBase <object> { Succeed = true, Data = new { url, handlers } }; await WriteResponseAsync(context, response); }
internal static async Task ExecuteAsync(HttpContext context, MicroServiceOption option) { //发现服务 if (context.Request.Path.Value.EndsWith("/discover")) { await ProcessDiscoverAsync(context, option); } //健康检查 else if (context.Request.Path.Value.EndsWith("/health_check")) { context.Response.StatusCode = 200; } //执行请求 else if (context.Request.Path.Value.EndsWith("/execute")) { await ProcessExecuteAsync(context); } }
public MicroServiceMiddleware(RequestDelegate next, IServiceProvider serviceProvider, MicroServiceOption option) { this.next = next; this.serviceProvider = serviceProvider; this.option = option; }