/// <summary> /// 添加代理转发规则 /// </summary> /// <param name="rule"></param> public static void AddProxyRule(ProxyOptions rule) { if (options == null) { options = new ProxyOptionGroup { Excludes = new List <string>(), Options = new List <ProxyOptions>() }; } options.Options.Add(rule); }
/// <summary> /// 找到转发匹配规则 /// </summary> /// <param name="options">规则组</param> /// <param name="path">请求路径</param> /// <returns>规则项</returns> public static ProxyOptions MatchProxyRule(this string path, ProxyOptionGroup options) { ProxyOptions op = null; if (options.Excludes != null && options.Excludes.Exists(e => path.StartsWith(e, StringComparison.CurrentCultureIgnoreCase))) { return(op); } foreach (var item in options.Options) { if (item.Excludes != null && item.Excludes.Exists(e => path.StartsWith(e, StringComparison.CurrentCultureIgnoreCase))) { continue; } if (item.MatchReg.IsMatch(path)) { op = item; break; } } return(op); }